SQL Server删除表及删除表中数据的方法,sqlserver

Source: Internet
Author: User


This article describes how to delete a table and how to delete data in the table in SQL Server. There are two ways to delete table data: delete and truncate. What is the difference between delete and truncate?

SQL Server, the oldest version we are currently using should be SQL Server 2000. Should it be earlier ?! From SQL Server 2000, to SQL Server 2012, etc, T-SQL processing capacity is getting stronger and stronger. Today we will talk about how to use the T-SQL script to delete a table and delete data in the table.

Deleting a table and deleting table data are two different things! Deleting a table means that the database table is completely erased no matter whether there is any data in the table. Deleting table data only deletes the data rows in the table, but the table results still exist. You can also insert new data into the table.

The T-SQL statement for deleting a table is:

Drop table <table Name>

Drop means dropping. drop table means deleting a table completely.

There are two ways to delete table data: delete and truncate.

Delete is used as follows:

Delete from <Table Name> [where condition]

The usage of truncate is as follows:

Truncate table <table Name>

The differences between delete and truncate are as follows:

1. delete can delete one or more data records in a table or all data records. truncate can only delete all data in a table.

2. After the delete operation deletes table data, the identification field cannot be reused. That is to say, if you delete the row of data with id = 10 (if id is the id field), you cannot insert another row of data so that id = 10.

3. After truncate deletes the table data, it indicates that the table is restored to the initial state. The default value is 1, that is, after truncate, insert another data entry, id = 1.

I would like to introduce so much about how SQL Server deletes and deletes table data. I hope this will be helpful to you and thank you very much for your support for the help House website!

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.