What is TSQL and how is it different from SQL, PL/SQL, and PL/pgSQL?
tl:dr:
- SQL (Structured Query Language) is a standard language used in managing data in almost all relational database management systems (RDBMS) such as PostgreSQL, MySQL, SQL Server, Oracle, DB2, Informix, etc.
- TSQL is a proprietary procedural language used by Microsoft SQL Server.
- PL/SQL is a proprietary procedural language with embedded SQL used by Oracle.
- PL/pgSQL is a procedural language used by PostgreSQL.
What is SQL?
SQL is the query language used for communicating with data held in a relational database. It’s used as the standard language across all relational database management systems. However, each database management system has its own extensions thus the syntax and some functionalities might be different.
SQL was developed by IBM in the early 1970s under the name SEQUEL. Then due to some level trademark issues, it’s renamed to SQL, though a lot of people still call it sequel today.
What is TSQL?
TSQL, or T-SQL, shorts for Transaction-SQL, is an enhanced version of SQL which has with some extensions built on top of it. TSQL was originally developed by Sybase & now is owned by Microsoft.
TSQL adds some advanced features to SQL to make it more powerful such as declared variables, transaction control, error and exception handling, string operations, date and time processing.
These additions make T-SQL comply with the Turing completeness test, a test that determines the universality of a computing language. SQL is not Turing complete and is very limited in the scope of what it can do.
What is PL/SQL?
PL/SQL or Procedural Language/SQL is another extended form of SQL which is used by Oracle for their database.
The main difference between the TSQL and PL/SQL is the way they handle variables, stored procedures, and built-in functions. TSQL is also considered easier and simpler to understand while PL/SQL seems to be more complicated.
What is PL/pgSQL?
PL/PgSQL is a PostgreSQL-specific procedural language based on SQL. Similar to TSQL and PL/SQL, it adds some advanced features to SQL such as loops, variables, error and exception handling, etc.
PL/pgSQL functions are considered as the better replacement for SQL functions in saving the client/server communication cost, this can result in a considerable performance increase.
The common differences between PL/pgSQL and TSQL are some data types such as BOOL vs BIT, or timestamp vs date time; some functions such as now() vs getdate(); and DDL shortcuts such as SERIAL vs INT IDENTITY(1,1). However, they are pretty alike.
Need a good GUI Tool for managing relational databases and practising SQL? Try TablePlus. It’s is a modern, native GUI that allows you to simultaneously manage multiple databases such as MySQL, MariaDB, PostgreSQL, SQLite, Microsoft SQL Server… faster and easier.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.