Download presentation
Presentation is loading. Please wait.
Published bySilas Cooper Modified over 6 years ago
1
T-SQL Transact - Structured Query Language (Microsoft)
PL/SQL – Procedural Language/SQL (Oracle)
2
T-SQL definition Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to the SQL (Structured Query Language) used to interact with relational databases. T-SQL expands on the SQL standard to include procedural programming, local variables, various support functions for string processing, date processing, mathematics, etc. and changes to the DELETE and UPDATE statements. Transact-SQL is central to using Microsoft SQL Server. All applications that communicate with an instance of SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface of the application. Stored procedures in SQL Server are executable server-side routines. The advantage of stored procedures is the ability to pass parameters.
3
Declare and set local variables
NVARCHAR(30) = 'Some Name' = Name FROM Sales.Store WHERE CustomerID = 100
4
If – else with begin and end blocks
IF DATEPART(dw, GETDATE()) = 7 OR DATEPART(dw, GETDATE()) = 1 BEGIN PRINT 'It is the weekend.' PRINT 'Get some rest on the weekend!' END ELSE PRINT 'It is a weekday.' PRINT 'Get to work on a weekday!'
5
While loops DECLARE @i INT SET @i = 0 WHILE @i < 5 BEGIN
PRINT 'Hello world.' + 1 END
6
Delete (and Update) are allowed in T-SQL
DELETE u FROM users AS u INNER JOIN user_flags AS f ON u.id = f.id WHERE f.name = 'idle'
7
Transaction commit with rollback via TRY-CATCH
BEGIN TRAN BEGIN TRY -- execute each statement INSERT INTO MYTABLE(NAME) VALUES ('ABC') INSERT INTO MYTABLE(NAME) VALUES ('123') -- commit the transaction COMMIT TRAN END TRY BEGIN CATCH -- roll back the transaction because of error ROLLBACK TRAN END CATCH
8
Bulk Insert with transaction rollback
BEGIN TRANSACTION BEGIN TRY BULK INSERT dbo.BulkDataTable FROM 'C:\TestFiles\Bulk3.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', ROWS_PER_BATCH = 10000, TABLOCK ) COMMIT TRANSACTION END TRY BEGIN CATCH ROLLBACK TRANSACTION END CATCH
9
PL/SQL (Oracle) PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database (since version 6 - stored PL/SQL procedures/functions/packages/triggers since version 7), TimesTen in-memory database (since version ), and IBM DB2 (since version 9.7).[1] Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database. PL/SQL works analogously to the embedded procedural languages associated with other relational databases. For example, Sybase ASE and Microsoft SQL Server have Transact-SQL, PostgreSQL has PL/pgSQL (which emulates PL/SQL to an extent), and IBM DB2 includes SQL Procedural Language,[2] which conforms to the ISO SQL’s SQL/PSM standard.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.