SQL Language Reference
This section provides comprehensive documentation for the SQL Server Transact-SQL (T-SQL) language. Discover the syntax, functions, and statements used to interact with and manage SQL Server databases.
Core Concepts
Understanding the fundamental building blocks of T-SQL is crucial for effective database development. Explore topics such as:
- Data Types: Learn about the various data types available in SQL Server and their appropriate uses.
- Operators: A guide to arithmetic, comparison, logical, and bitwise operators.
- Expressions: How to construct expressions that evaluate to a single value.
- Constraints: Defining rules to maintain data integrity, such as PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and DEFAULT.
Statements and Commands
Master the essential T-SQL statements for data manipulation, definition, and control.
Data Manipulation Language (DML)
- SELECT: Retrieve data from one or more tables.
- INSERT: Add new rows of data into a table.
- UPDATE: Modify existing data in a table.
- DELETE: Remove rows from a table.
- MERGE: Perform INSERT, UPDATE, or DELETE operations on a target table based on the results of a join with a source table.
Data Definition Language (DDL)
- CREATE TABLE: Define new tables in the database.
- ALTER TABLE: Modify the structure of an existing table.
- DROP TABLE: Remove a table and all its data.
- CREATE INDEX: Improve query performance by creating indexes.
- CREATE VIEW: Define virtual tables based on the results of a stored query.
Data Control Language (DCL)
Built-in Functions
SQL Server provides a rich set of built-in functions for various tasks:
Category | Function Name | Description |
---|---|---|
Aggregate | AVG() | Calculates the average value of a column. |
Aggregate | COUNT() | Counts the number of rows or non-null values in a column. |
Aggregate | MAX() | Returns the maximum value in a set of values. |
Aggregate | MIN() | Returns the minimum value in a set of values. |
Aggregate | SUM() | Calculates the sum of values in a numeric column. |
String | CONCAT() | Concatenates strings. |
String | LEN() | Returns the length of a string. |
String | LOWER() | Converts a string to lowercase. |
String | UPPER() | Converts a string to uppercase. |
Date and Time | GETDATE() | Returns the current database system date and time. |
Date and Time | DATEPART() | Returns a specified part of a date as an integer. |
Mathematical | ABS() | Returns the absolute value of a numeric expression. |
Mathematical | ROUND() | Rounds a numeric value. |
Advanced Topics
- Stored Procedures: Creating and managing reusable blocks of T-SQL code.
- Triggers: Executing T-SQL code automatically in response to data modification events.
- Cursors: Processing rows in a database one at a time.
- Transactions: Ensuring data consistency and integrity through ACID properties.
For detailed syntax and examples of each statement and function, please navigate through the sidebar or use the search functionality.