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