Wednesday 18 September 2013

Delete ,Truncate and Drop command in Sql.

DELETE :-
Delete statement is used to delete rows form table.

Syntax:-
DELETE FROM table [WHERE_CONDITION]

Note:- Here where clause  is optional.If you do not include in the query then it will delete all the rows from the table. If you want to delete some particular row or rows the you have to include where clause in the query.So be careful while deleting the data from table.
If you want to delete single row from the table for employee having id=100, then use below query.
DELETE FROM employee WHERE id=100;

To delete all rows from employee table, the query would be like

DELETE FROM employee;

Truncate:-
Truncate command is used to delete  all the rows from the table and free the space conating table.
Syntax:-
TRUNCATE TABLE table_name;

Example:-
If you want to delete the records from the Employee table , the query would like this.
TRUNCATE TABLE Employee;

Drop:-
Sql Drop command is used to remove an object from the database. If you want to drop a table, all the rows in the table are deleted and the table structure is removed from the database. Once a table is dropped
we cannot get it back means roll back is not possible in DROP.

Syntax :-
DROP TABLE table_name;

Example:- Drop the employee table, the query would like this


DROP TABLE Employee;

No comments:

Post a Comment

Note: only a member of this blog may post a comment.