CREATE Statements
Use CREATE statements to define new database objects such as tables, views, and procedures.
CREATE TABLE dbo.Employee (
EmployeeID INT PRIMARY KEY,
FirstName NVARCHAR(50),
LastName NVARCHAR(50),
HireDate DATE
);
SELECT Statement
The SELECT statement retrieves data from one or more tables.
SELECT EmployeeID, FirstName, LastName
FROM dbo.Employee
WHERE HireDate > '2020-01-01'
ORDER BY HireDate DESC;
INSERT Statement
Insert new rows into a table.
INSERT INTO dbo.Employee (EmployeeID, FirstName, LastName, HireDate)
VALUES (101, N'Jane', N'Doe', GETDATE());
UPDATE Statement
Modify existing rows.
UPDATE dbo.Employee
SET LastName = N'Smith'
WHERE EmployeeID = 101;
DELETE Statement
Remove rows from a table.
DELETE FROM dbo.Employee
WHERE EmployeeID = 101;
Built-in Functions
SQL Server provides a rich set of functions for string, date, mathematical, and system operations.
- LEN – Returns the number of characters of the specified string.
- GETDATE – Returns the current database system timestamp.
- DATEADD – Adds a specified number of units to a date.
- ISNULL – Replaces NULL with a specified replacement value.