Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between drop table and delete table in SQL Server?

In SQL Server, what is the difference between the following two-

  • Right click on a database object (table/view) and opt for Drop table (i.e. Script table as -> DROP To -> New Query Editor Window)

  • Right click on a database object (table/view) and opt for Delete.

I tried them both and both perform the same action. Any reason for having two options for the same thing? Is the Delete option just a crude way of dropping the DB object?

Just for the record - I'm using SS2008.

like image 989
Arnkrishn Avatar asked Jul 17 '09 15:07

Arnkrishn


People also ask

What is the difference between drop table and DELETE table in SQL?

DELETE is a Data Manipulation Language command, DML command and is used to remove tuples/records from a relation/table. Whereas DROP is a Data Definition Language, DDL command and is used to remove named elements of schema like relations/table, constraints or entire schema.

What is the difference between drop table and truncate table and DELETE table?

The TRUNCATE command is a Data Definition Language Command. The DELETE command deletes one or more existing records from the table in the database. The DROP Command drops the complete table from the database. The TRUNCATE Command deletes all the rows from the existing table, leaving the row with the column names.

What is the difference between the DELETE and DROP command?

DELETE command is used to remove some or all the tuples from the table. On the other hand, the DROP command is used to remove schema, table, domain or Constraints from the database. DELETE is a Data Manipulation Language command whereas, DROP is a Data Definition Language command.

Does SQL drop table DELETE data?

When SQL Server drops a table, it also deletes all data, triggers, constraints, permissions of that table. Moreover, SQL Server does not explicitly drop the views and stored procedures that reference the dropped table.


1 Answers

DROP will delete all data and the table structure as well.

DELETE will delete the data but the table structure will remain the same and we can still rollback the data. Also with DELETE you can use the where condition i.e. to delete only certain records.

like image 135
NiKhila Kota Avatar answered Oct 23 '22 06:10

NiKhila Kota