SELECT MAX(UnitPrice) AS HighestPrice, MIN(UnitPrice) AS LowestPrice
FROM Products
The query above gets the highest and lowest prices for the Products table in the Northwind database
SELECT MAX(UnitPrice) AS HighestPrice, MIN(UnitPrice) AS LowestPrice
FROM Products
SELECT FirstName + ' ' + LastName AS Employee, HireDate
FROM Employees
WHERE DATEPART(yyyy,HireDate) = 1994

SELECT FirstName + ' ' + LastName AS Employee, HireDate
FROM Employees
WHERE DATEPART(MM,HireDate) = 10

SELECT COUNT(*) AS NumberOfRows
FROM Customers

SELECT COUNT(Region) AS NumberOfRows
FROM Customers

SqlCommand cmd = new SqlCommand("INSERT INTO Users (" +
"LoginName," +
"FirstName," +
"LastName," +
"Password," +
"Email," +
"DOB," +
"Sex" +
") VALUES (" +
"@Email," +
"@FirstName," +
"@LastName," +
"@Password," +
"@Email," +
"@DOB," +
"@Sex)" +
" Select Scope_Identity();",conn);
int UserId = (int)cmd.ExecuteScalar();
SELECT *
FROM Products
WHERE SupplierID NOT IN (1,2)
SELECT *
FROM Products
WHERE SupplierID IN (1,2)
SELECT CategoryID,ProductName,UnitPrice
FROM Products
WHERE CategoryID = 1 OR CategoryID =2 AND UnitPrice < 15
SELECT CategoryID,ProductName,UnitPrice
FROM Products
WHERE (CategoryID = 1 OR CategoryID =2) AND UnitPrice < 15
SELECT OrderID, ShippedDate
FROM Orders
WHERE ShippedDate IS NULL
SELECT OrderID, ShippedDate
FROM Orders
WHERE ShippedDate IS NOT NULL
SELECT OrderID, OrderDate
FROM Orders
WHERE OrderDate BETWEEN '1997-12-24' AND '1998-01-01'
CREATE TABLE Books
(
Id INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
Book XML NOT NULL
);

INSERT INTO Books(Book)
VALUES(
CAST ( '<book>
<author>Bill King</author>
<title>ACME Consulting: An Inside Look</title>
<publisher>ACME Publishing</publisher>
<language>Swahili</language>
</book>' AS XML));
CREATE TABLE Books
(
Id INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
Book XML NOT NULL
);

INSERT INTO Books(Book)
VALUES(
CAST ( '<book>
<author>Bill King</author>
<title>ACME Consulting: An Inside Look</title>
<publisher>ACME Publishing</publisher>
<language>Swahili</language>
</book>' AS XML));
BEGIN TRANSACTIONThe above query will only execute if there are no errors, if there's an error the transaction will be rolled back. That's it, that's the whole concept of what a transaction is, if there are no errors then you should get the following message.
DELETE Products WHERE ProductID = 87
COMMIT TRANSACTION
BEGIN TRANSACTIONThe above query rolls back the query if there's an error. Notice the IF @@Error condition.
INSERT INTO Customers(CustomerID,CompanyName)
VALUES ('ACME','ACME Company')
SAVE TRANSACTION StartOrder
INSERT INTO Orders(OrderID,CustomerID)
VALUES (10999,'ACME')
IF @@Error <> 0 ROLLBACK TRANSACTION StartOrder
INSERT INTO [Order Details](OrderID,ProductID,UnitPrice,Quantity,Discount)
VALUES (10999,14,23.25,1,0)
COMMIT TRANSACTION
The above query will only execute if there are no errors, if there's an error the transaction will be rolled back. That's it, that's the whole concept of what a transaction is, if there are no errors then you should get the following message.
BEGIN TRANSACTION
DELETE Products WHERE ProductID = 87
COMMIT TRANSACTION
The above query rolls back the query if there's an error. Notice the IF @@Error condition.
BEGIN TRANSACTION
INSERT INTO Customers(CustomerID,CompanyName)
VALUES ('ACME','ACME Company')
SAVE TRANSACTION StartOrder
INSERT INTO Orders(OrderID,CustomerID)
VALUES (10999,'ACME')
IF @@Error <> 0 ROLLBACK TRANSACTION StartOrder
INSERT INTO [Order Details](OrderID,ProductID,UnitPrice,Quantity,Discount)
VALUES (10999,14,23.25,1,0)
COMMIT TRANSACTION
The query above gets the highest and lowest prices for the Products table in the Northwind database
SELECT MAX(UnitPrice) AS HighestPrice, MIN(UnitPrice) AS LowestPrice
FROM Products
The query above returns the number of rows in the Customers table
SELECT COUNT(*) AS NumberOfRows
FROM Customers

The query above counts the number of rows for the column "Region" that are not NULL
SELECT COUNT(Region) AS NumberOfRows
FROM Customers

SELECT ProductName
FROM Products
WHERE SOUNDEX(ProductName) = SOUNDEX('Chief')