SQL Server methods for deleting tables and deleting data in tables

Source: Internet
Author: User

The T-SQL statement that deletes the table is:

DROP table < table name >

Drop is discarded, and drop table means that a table is completely erased.

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 usage of truncate is as follows:

TRUNCATE TABLE < name >

The difference between delete and truncate is as follows:

1. Delete can delete one or more data from a table, or delete all data, and truncate can only delete all the data in the table.

2. After delete deletes the table data, the identity field cannot be reused. In other words, if you delete the row of id=10 (if the ID is an identity field), you may not be able to insert a 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 one more data, id=1.

SQL Server methods for deleting tables and deleting data in tables

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.