Saturday, 14 May 2016

How to formate in sql


select ProductName, Price, FORMAT(Now(),'YYYY-MM-DD') AS PerDate
from Product;

How to use now function in sql

select ProductName, Price, Now() AS PerDate
from Product;

How to get round price in sql

select ProductName, ROUND(Price,0) AS RoundedPrice
from Product;

How to get sum value in sql

select SUM(Quantity) AS TotalOrdered from OrderDetail;

How to get min value in sql

select MIN(Price) AS smallOrderPrice from Product;

How to get maximum value in sql

select MAX(Price) AS HighestPrice form Product;

How to count() function in sql



select COUNT(ClientID)AS OrderFormClientID1 form Order where ClientID=1;

How to average price value in sql



select ProName, Price From Product where Price>(select avg(Price)from Product);

How to database & table drop in sql

Table:

DROP TABLE Client(table name).


Database:


DROP DATABASE CompanyManagementSystem(database name).


How to create foreign key in sql

Order table(ord_Id int NOT NULL,OrderNo int NOT NULL,Client_Id int,PRIMARY KEY (ord_Id),CONSTRAINT fk_ClientOrder FOREIGN KEY (Client_Id)REFERENCES Client(Client_Id))

How to create primary key in sql

Client Table
(
Client _Id int NOT NULL PRIMARY KEY,
Name varchar(50) NOT NULL,
Address varchar(250),
City varchar(15)
)

Client ID is a primary key.


How to union operator in sql database

SELECT City FROM Client
UNION
SELECT City FROM Supplier
ORDER BY City;

How to full join in sql

SELECT Client.ClientName, Product.ProductID
FROM Client
FULL OUTER JOIN Product
ON Client.ClientID=Product.ClientID
ORDER BY Client.ClientName;

How to right join in sql

SELECT Product.ProductID, Client.Name
FROM Product
RIGHT JOIN Client
ON Product.ClientID=Client.ClientID
ORDER BY Product.ProductID;

How to left join in sql

SELECT Client.ClientName, Product.ProductID
FROM Client
LEFT JOIN Product
ON Client.ClientID=Product.ClientID
ORDER BY Client.ClientName;

How to INNER Join in sql database

SELECT Client.ClientName, Orders.OrderID
FROM Client
INNER JOIN Orders
ON Client.ClientID=Orders.ClientID
ORDER BY Client.ClientName; 

How to table join in sql

SELECT Product.ProductID, Client.ClientName, Product.ProductDate
FROM Product
INNER JOIN Client
ON Product.ClientID=Client.ClientID;

How to delete data in database sql server



DELETE FROM Client
WHERE Name='Dovi' AND Clientname='Mmoi';


All Data Delete:

DELETE FROM Client;

How to update data in sql server database

UPDATE Client
SET Name='Dovi', City='London'
WHERE CustomerName='Musha';

Click to execute .

How to insert data in sql database 

INSERT INTO Client
VALUES (name,address,City,...);
 

Column name and values :

INSERT INTO Client(name,address,city,...)
VALUES (kolom,span,vigas,...);



How to create table in sql server

Client Table :


Product Table:



Output