Documente Academic
Documente Profesional
Documente Cultură
Drop Database
Create table
DROP TABLE
TRUNCATE TABLE
ALTER TABLE
ADD
DROP
MODIFY(ALTER)
CREATE
ALTER
DROP
PRIMARY KEY
FORIGN KEY
DEFAULT
INDEX
VIEW
INSERT INTO
UPDATE
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE
-PTO-
SELECT QUERY
SELECT * FROM Customers;
DISTINCT
WHERE
Operator Description
= Equal
<> Not equal. Note: In some versions of SQL this operator may
be written as !=
ORDER BY
NULL VALUE
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
TOP
MIN MAX
SELECT COUNT(ProductID)
FROM Products;
SELECT AVG(Price)
FROM Products;
SELECT SUM(Quantity)
FROM OrderDetails;
LIKE
WHERE CustomerName LIKE 'a%' Finds any values that starts with "a"
WHERE CustomerName LIKE '%a' Finds any values that ends with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second
position
WHERE CustomerName LIKE Finds any values that starts with "a" and are
'a_%_%' at least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that starts with "a" and ends
with "o"
WILD CARD
//STARTS FROM B OR S OR P
IN
BETWEEN
ALIAS
SELECT column_name(s)
FROM table_name AS alias_name;
SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' +
Country AS Address
FROM Customers;
INNER JOIN
Left join
RIGHT JOIN
SELF JOIN
CROSS JOIN
EQUI JOIN
UNION
GROUP BY
HAVING
EXIST
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId =
Suppliers.supplierId AND Price < 20);
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId =
Suppliers.supplierId AND Price = 22);
ANY OR ALL
SELECT ProductName
FROM Products
WHERE ProductID = ANY (SELECT ProductID FROM OrderDetails WHERE Quantity
= 10);
SELECT ProductName
FROM Products
WHERE ProductID = ANY (SELECT ProductID FROM OrderDetails WHERE Quantity
> 99);
SELECT ProductName
FROM Products
WHERE ProductID = ALL (SELECT ProductID FROM OrderDetails WHERE Quantity
= 10);
SELECT INTO
The SQL Server ISNULL() function lets you return an alternative value when an
expression is NULL:
--Select all:
/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customers WHERE (CustomerName LIKE 'L%'
OR CustomerName LIKE 'R%' /*OR CustomerName LIKE 'S%'
OR CustomerName LIKE 'T%'*/ OR CustomerName LIKE 'W%')
AND Country='USA'
ORDER BY CustomerName;