Menu

Wednesday, 15 January 2014

SQL Statement Type


DDL (Data Definition Language) - CREATE, ALTER, DROP

Creating Table
CREATE TABLE EMP (
EmpNo int,
EName VarChar(25),
Job nvarChar(10) ,
Hiredate Datetime,
)
Example –
EmpNo
EName
Job
Hiredate

Adding New Column in Table
ALTER TABLE EMP
ADD DeptNo int;
Examples –
EmpNo
EName
Job
Hiredate
DeptNo

Remove Column in Table
ALTER TABLE EMP
DROP Hiredate;
Examples –
EmpNo
EName
Job
DeptNo

Delete Table Structure forever
DROP Table Emp;



DML (Data Manipulation
Language) SELECT, INSERT, UPDATE, DELETE


SELECT
Select * FROM EMP;
INSERT
Insert INTO EMP Values(‘2001’,’Suryagroops’,’xyz’)
UPDATE
Update EMP Set  EName = ‘Moon’;
DELETE
Delete FROM EMP;


DCL (Data Control
Language) GRANT, REVOKE, ROLLBACK, COMMIT


GRANT
REVOKE
You can grant users various privileges to tables. These
Privileges can be any combination of select, insert, update, delete,
References, alter, and index.
It’s opposite to grant. It get the privileges back.

EXAMPLE:
Grant select on SCOTT.EMP to USER1.EMP;

EXAMPLE :
Revoke select on SCOTT.EMP to USER1.EMP;



TCL (Transaction Control Language)


COMMIT
ROLLBACK
SAVEPOINT
Use the COMMIT statement to end your current transaction
And make permanent all changes performed in the transaction.

Use the ROLLBACK statement to undo work done in the
Current transaction.

It defines breakpoints for a transaction to allow partial
Rollbacks.


No comments: