T-SQL is the procedural programming language built into
SQL Server. It's functionally the equivalent of PostgreSQL's PL/pgSQL.
It looks a bit odd because it has unique conventions like:
- Semicolons are not required at the end of each line of code
- Variable names always are prefixed with @ signs
- IF statements do not need to be closed by END IF's
- Temporary tables are automagic if the table name has a # prefix
CREATE TABLE customers (
id int IDENTITY,
company varchar(20),
huge_profits money
);
CREATE PROCEDURE tsql_101
DECLARE
@stop_innovating_in_a_mature_industry varchar(20),
@check_out_tpostgres_on_linux_osx_win varchar(20)
BEGIN
IF EXISTS (SELECT huge_profits FROM customers WHERE company = 'Microsoft')
SET @stop_innovating_in_a_mature_industry = 'Yes'
ELSE
SET @check_out_tpostgres_on_linux_osx_win = 'Definitely'
PRINT 'Enterprise tPostgres is a No Brainer.'
END
|