totn SQL Server

SQL Server Tutorial

SQL Server is a relational database technology developed by Microsoft.

Transact-SQL (T-SQL) is an extension of SQL that is used in SQL Server. Transact-SQL is closely integrated into the SQL language, yet it adds programming constructs that are not native to SQL.

Our tutorial will start with the basics of SQL Server such as how to retrieve and manipulate data. Then we will move to the more advanced topics such as how to create tables, logins, users, functions, and procedures. We will conclude with a review of the functions that are proprietary to Transact-SQL.

With this tutorial, you should be on your way to becoming proficient in SQL Server and Transact-SQL.

Prerequisites

There are no prequisities for this SQL Server tutorial. You should be able to easily understand this tutorial and learn the basic concepts of SQL Server as you progress to the more advanced topics.

Now, let's get started!

Start Tutorial

Or jump directly to a topic in SQL Server:

SQL Server (Transact-SQL) Functions

Functions - Alphabetical SQL Server (Transact-SQL) Functions listed alphabetically
Functions - Category SQL Server (Transact-SQL) Functions listed by category

SQL Server Keys, Constraints and Indexes

Primary Keys Create, alter, drop, enable and disable primary keys
Foreign Keys Create, drop, enable and disable foreign keys
Unique Constraints Create, add, and drop unique constraints
Check Constraints Create, alter, drop, enable and disable check constraints
Indexes Create, rename and drop indexes (Performance tuning)

SQL Server Privileges

Grant/Revoke Privileges Grant or revoke privileges (permissions)
Change Password Change a password for a user/login

SQL Server Database Administration

Logins Identity used to connect to a SQL Server instance (create, alter, drop)
Users Database user to log into SQL Server (create, drop)

SQL Server Programming

Functions Create and drop functions
Procedures Create and drop stored procedures
Literals (Constants) String, integer, decimal, and datetime literals
Declare Variables Declare variables and set variables
Loops and Conditional Statements WHILE Loop, IF...ELSE statement
Sequences (Autonumber) Create and drop sequences
Comments within SQL How to create comments within your SQL statement

SQL Server Comparison Operators

Comparison Operators Operators such as =, <>, !=, >, <, and so on

SQL Server Query Types

SELECT Statement Retrieve records from a table
SELECT TOP Statement Retrieve records from a table and limit results
SELECT INTO Statement Create a new table with columns and data from another table
INSERT Statement Insert records into a table
UPDATE Statement Update records in a table
DELETE Statement Delete records from a table
DELETE TOP Statement Delete records and limit number of deletions
TRUNCATE TABLE Statement Delete all records from a table (no rollback)
UNION Operator Combine 2 or more result sets (removes duplicates)
UNION ALL Operator Combine 2 or more result sets (includes duplicates)
INTERSECT Operator Intersection of 2 result sets
EXCEPT Operator Result set of one minus the result set of another
Subqueries A query within a query
PIVOT Clause Create a cross-tabulation query

SQL Server Joins

JOIN Tables Inner and Outer joins

SQL Server Aliases

ALIASES Create a temporary name for a column or table

SQL Server Clauses

DISTINCT Clause Retrieve unique records
FROM Clause List tables and join information
WHERE Clause Filter results
ORDER BY Clause Sort query results
GROUP BY Clause Group by one or more columns
HAVING Clause Restrict the groups of returned rows

SQL Server SQL Functions

COUNT Function Return the count of an expression
SUM Function Return the sum of an expression
MIN Function Return the min of an expression
MAX Function Return the max of an expression
AVG Function Return the average of an expression

SQL Server Conditions

AND Condition 2 or more conditions to be met
OR Condition Any one of the conditions are met
AND and OR Combine AND and OR conditions
LIKE Condition Use wildcards in a WHERE clause
IN Condition Alternative to multiple OR conditions
NOT Condition Negate a condition
IS NULL Condition Test for a NULL value
IS NOT NULL Condition Test for a NOT NULL value
BETWEEN Condition Retrieve within a range (inclusive)
EXISTS Condition Condition is met if subquery returns at least one row

SQL Server Tables and Views

CREATE TABLE Create a table
SELECT INTO Create a table from another table's definition and data
ALTER TABLE Add, modify or delete columns in a table; rename a table
DROP TABLE Delete a table
LOCAL TEMP TABLES Temporary tables that are distinct within modules and embedded SQL programs
GLOBAL TEMP TABLES Temporary tables that are distinct within SQL sessions
VIEW Virtual tables (views of other tables)

SQL Server Data Types

Data Types Data Types in SQL Server (Transact-SQL)

SQL Server Question and Answer

Question & Answer Various questions and answers