Wednesday 1 May 2013

TCL - Transaction control Language and Create Datebase statement

DCL - Data Control Language(Grant, Revoke )

Grant- is used to provide(grant permission) privileges for database objects.
Revoke-is used to deny(get back the permission) privileges.

TCL - Transaction control Language(Commit, Rollback)

Tcl-is used to control set of actions called transactions like insert, update, delete.
Transaction statement must start with BEGIN transaction_name followed by DML statements.
IF condition followed by BEGIN is IF condition start END is End of If condition

BEGIN TRAN
DELETE EMPloyee WHERE empno = 10
IF @@ROWCOUNT =1
BEGIN
COMMIT TRAN
PRINT 'EMPLOYEE DELETED'
END
ELSE
BEGIN
ROLLBACK TRAN
PRINT 'ROLLED BACK'
END


we use savepoints in TCL to save a particular transactions.
If we use savepoint it saves the transaction that takes place below it.

BEGIN TRAN
DELETE EMPloyee WHERE EmpNO=5
SAVE TRAN E1
DELETE EMPloyee WHERE EmpNO=4
SAVE TRAN E2
DELETE EMPloyee WHERE EmpNO=3
SELECT * FROM EMPloyee
ROLLBACK TRAN E2
SELECT * FROM EMPloyee
ROLLBACK TRAN E1
SELECT * FROM EMPloyee
COMMIT TRAN
SELECT * FROM EMP10



E1, E2 are save points we can able to rollback to any save point before transaction is committed. Once transaction committed changes made permanent .We cannot rollback to save point.

The CREATE DATABASE Statement
The CREATE DATABASE statement is used to create a database.
syntax:

create database database_name
Now we want to create a database called "siva".

create database siva
Now we want to use the created database called "siva".

syntax:
use database_name
use siva

0 comments:

Post a Comment