SQL Server methods for deleting tables and deleting data in tables _mssql

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.