Wednesday, 17 February 2021

3- Mysql Practical for class 12 CS and IP

 

 Write the difference between drop, delete and truncate command with example.

Drop:

Drop is a DDL (Data Definition Language) command of SQL.

Drop is used to remove an object completely just like remove database, table, view, index etc.

Syntax:

DROP object object_name

Examples:

DROP TABLE table_name;

table_name: Name of the table to be deleted.

DROP DATABASE database_name;

database_name: Name of the database to be deleted.


Delete:

Delete is a DML (Data Manipulation Language) command of SQL.

Delete is used to remove one or more rows from a table, view, index etc. We can use where clause with delete command. Delete remove one row at a time i.e. it remove rows one by one. It will not delete columns or structure of table.

Syntax:

delete from table_name where condition;

Examples:

delete from table_name;

table_name: Name of the table from which rows will be deleted.

Delete all rows from the table.

delete from table_name where condition;

delete specific rows on the bases of where clause condition.


Truncate:

Truncate is a DDL (Data Defination Language) command of SQL.

Truncate is used to remove all rows from a table, view, index etc. We can not use where clause with truncate command. Truncate remove all rows at once, but it will not delete structure of the table or any object.

Syntax:

delete from table_name where condition;

Examples:

trucate table_name;

table_name: Name of the table from which rows will be deleted.

Delete all rows from the table at once.


No comments:

Post a Comment