Manipulating data tables with T-SQL statements-deleting data

Source: Internet
Author: User
1. Delete the data in the table using the DELETE statement:
Grammar:
Delete from < table name > [where < delete condition;]
Delete is the meaning of the deletion
Where is the optional content can not add, but without conditions, delete the entire table
Example:
Delete from score table where name = ' Zhang San '
Meaning:
Delete the Zhang San information in the score table, or delete the entire score table if you don't add where
Attention:
Delete Deletes the entire record, does not delete a single field, that is, does not delete the empty table, so the column name does not appear after delete.
~ ~ Delete < column name > from < table name > ~ ~

2. Use the TRUNCATE TABLE statement to delete data from a table
Grammar:
TRUNCATE TABLE < name >
TRUNCATE TABLE is the meaning of deleting tables
Example:
TRUNCATE TABLE score Sheet
Meaning: Delete all data in the score table (record line)
Note: TRUNCATE TABLE is functionally similar to a DELETE statement without a WHERE clause.

两者的区别:1.truncate 语句不带where字句,只能删除整个表的数据。而delete可以带where,允许按条件删除某些数据。2.truncate语句不记录事务日志,所以删除的数据*不能通过事务日志恢复*。而delete会记录,能恢复。3.truncate语句删除表中所有行,标识符列会重置为0。而delete不会重置标识符列。4.truncate语句不能用于外键约束引用的表。

Manipulating data tables with T-SQL statements-deleting data

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.