My Account Subscribe Help About
Sign In | Register FREE
Friday, April 10, 2026
Ceasefire or no ceasefire, the Middle East's reshuffling is not yet doneMan arrested after baby girl dies from dog biteMan jailed for killing abused wife who jumped from bridgeMelania Trump denies ties to Jeffrey Epstein and urges hearing for survivorsSimple guide: How the Iran war is affecting the cost of holidays, food and clothesMen behind 'Tripadvisor for people smugglers' jailed for 19 yearsIreland protesters willing to 'close the country' over fuel costsEU fingerprint and photo travel rules come into forceIran conflict will define us for a generation, says PMBafta fell short in duty of care when racial slur was shouted, review findsExtra £5m pledged for patrolling places of worship in London and ManchesterLebanon says ceasefire must be in place before Israel talks'Endless fears': Even if fighting stops, the damage to Iran's children will endureHow many ships are crossing the Strait of Hormuz?Want to help garden birds? Don't feed them in warmer months, says RSPBCan stats help you find the Grand National winner?Ten cases a day - 'blitz courts' could tackle the Crown Court backlogThis coat cost $248 in illegal tariffs. Will he ever get the money back?From a smuggled harmonica to Artemis' playlist - the history of music in spaceLava soars into air as Hawaii's Kilauea volcano erupts againWeekly quiz: What might have made Paddington panic about his marmalade?LeBron and Bronny James record first son-to-father assist in NBA history'I was in a slump - now my art is in Billie Eilish's house'Labrinth not involved in Euphoria's third seasonWhite House staff told not to place bets on prediction marketsRussia and Ukraine agree to Orthodox Easter truceBBC News appIs Defence Secretary Pete Hegseth waging a holy war against Iran?Defence secretary interview on Russian submarine operationWhat version of Tyson Fury will turn up this weekend?
FDN » SQL Server » Transact-SQL Quick Reference

Transact-SQL Quick Reference

Transact-SQL Quick Reference

Transact-SQL (T-SQL) is Microsoft's proprietary extension to SQL. This reference covers the most commonly used statements and functions in SQL Server 2000.

Data Definition

-- Create a table
CREATE TABLE Employees (
    EmployeeID  int           IDENTITY(1,1) PRIMARY KEY,
    FirstName   varchar(50)   NOT NULL,
    LastName    varchar(50)   NOT NULL,
    Email       varchar(100)  NULL,
    HireDate    datetime      NOT NULL DEFAULT GETDATE(),
    Salary      money         NULL,
    DeptID      int           NULL REFERENCES Departments(DeptID)
)

-- Add a column
ALTER TABLE Employees ADD Phone varchar(20) NULL

-- Create an index
CREATE INDEX IX_Employees_LastName ON Employees (LastName)

-- Create a unique constraint
ALTER TABLE Employees ADD CONSTRAINT UQ_Email UNIQUE (Email)

Data Manipulation

-- Insert
INSERT INTO Employees (FirstName, LastName, Email, DeptID)
VALUES ('John', 'Smith', 'jsmith@corp.flamenet.io', 1)

-- Update
UPDATE Employees SET Salary = 55000 WHERE EmployeeID = 1

-- Delete
DELETE FROM Employees WHERE EmployeeID = 1

-- Select with JOIN
SELECT e.FirstName, e.LastName, d.DeptName
FROM Employees e
INNER JOIN Departments d ON e.DeptID = d.DeptID
WHERE e.HireDate >= '2001-01-01'
ORDER BY e.LastName

-- Aggregate functions
SELECT DeptID, COUNT(*) AS EmpCount, AVG(Salary) AS AvgSalary
FROM Employees
GROUP BY DeptID
HAVING COUNT(*) > 5

Common Functions

FunctionExampleResult
GETDATE()SELECT GETDATE()Current date/time
DATEADD()DATEADD(day, 30, GETDATE())30 days from now
DATEDIFF()DATEDIFF(year, HireDate, GETDATE())Years employed
ISNULL()ISNULL(Email, 'N/A')Replace NULL
CAST()CAST(Salary AS varchar)Type conversion
SUBSTRING()SUBSTRING(LastName, 1, 3)First 3 chars
LEN()LEN(FirstName)String length
@@IDENTITYSELECT @@IDENTITYLast inserted identity
« Back to SQL Server « Back to FDN