Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Difference between SQL(Structured Query Language) and T-SQL(Transact-SQL).
SQL (Structured Query Language) and T-SQL (Transact-SQL) are both used to interact with relational databases. SQL is the standard query language common across all RDBMS platforms, while T-SQL is Microsoft's proprietary procedural extension to SQL used specifically with SQL Server.
SQL (Structured Query Language)
SQL is a non-procedural, declarative language used by database engines to create, modify, and query databases. You tell the database what you want, not how to get it. SQL is standardized by ANSI/ISO and is common across RDBMS platforms like MySQL, PostgreSQL, Oracle, and SQL Server.
Example
-- Standard SQL: simple query SELECT name, salary FROM employees WHERE department = 'Engineering' ORDER BY salary DESC;
T-SQL (Transact-SQL)
T-SQL is a procedural extension to SQL developed by Microsoft for SQL Server. It adds programming features like local variables, flow control (IF, WHILE), error handling (TRY...CATCH), stored procedures, and batch processing. It is similar to Oracle's PL/SQL.
Example
-- T-SQL: procedural logic with variables and flow control
DECLARE @bonus DECIMAL(10,2);
DECLARE @salary DECIMAL(10,2);
SELECT @salary = salary FROM employees WHERE id = 101;
IF @salary > 50000
SET @bonus = @salary * 0.10;
ELSE
SET @bonus = @salary * 0.15;
PRINT 'Bonus: ' + CAST(@bonus AS VARCHAR);
Key Differences
| Feature | SQL | T-SQL |
|---|---|---|
| Type | Non-procedural (declarative) | Procedural |
| Capabilities | Data manipulation and control (DDL, DML, DQL) | SQL features + variables, loops, error handling, stored procedures |
| Ownership | ANSI/ISO standard (used across all RDBMS) | Proprietary to Microsoft SQL Server |
| Query Execution | Queries submitted one at a time | Multiple queries can be submitted in batches |
| Advanced Features | Basic CRUD operations | Transaction control, exception handling, local variables |
| Comparable To | Standard across platforms | Similar to Oracle's PL/SQL |
Conclusion
SQL is the universal standard for querying relational databases across all platforms. T-SQL extends SQL with procedural programming capabilities like variables, loops, and error handling, making it specific to Microsoft SQL Server for writing complex business logic directly in the database.
