This article describes how to delete a table in SQL Server, and how to delete data from a table. Delete and truncate two methods when deleting table data, what's the difference between delete and truncate?
SQL Server, the oldest version we're basically using is SQL Server 2000, should there be no earlier versions?! From SQL Server 2000 to SQL Server 2005,2008,2012, T-SQL is becoming more and more capable of processing. Today we'll talk about how to use T-SQL scripts to delete tables and delete data from tables.
deleting tables and deleting table data it's two different things! Deleting a table means that the database table is completely erased, leaving nothing behind, regardless of the data in the table. Deleting table data deletes only the rows of data in the table, and the table results still exist, and you can insert new data into the table.
The T-SQL statement for the delete table is:
DROP table < table name >
Drop is meant to be discarded, and drop table indicates that a table is completely removed.
There are two ways to delete table data: Delete and truncate.
The use of delete is as follows:
Delete from < table name > [Where Condition]
The use of truncate is as follows:
TRUNCATE TABLE < name >
The difference between delete and truncate is as follows:
1, delete can delete one or more of the data in the table, you can delete all the data, and truncate can only delete all the data in the table.
2, delete the table data, the identity field can not be reused. That is, if you delete the row of id=10 (if ID is the identity field), you will not be able to insert a single piece of data for id=10.
3. After truncate deletes the table data, the identity resumes its initial state. The default is the initial value of 1, that is, after truncate, insert a piece of data, id=1.
About SQL Server Delete table and delete the data in the table to introduce so many people, I hope to help you, but also thank you very much for the cloud Habitat Community support site!