Get the App
SLTechnology News&Howtos  ›  Database  › 

How to delete data using the delete statement

Shulou Source: shulou.com Published: 2022-05-31 23:52:07 10月05日 Update

This article mainly introduces how to use delete sentence to delete data, the article is very detailed, has a certain reference value, interested friends must read it!

How do I delete data using the delete statement?

Create a temporary table to demonstrate the use of delete deletion in sqlserver syntax

IF OBJECT_ID ('tempdb..#tblDelete') IS NOT NULL DROP TABLE # tblDelete; CREATE TABLE # tblDelete (Code varchar (50), Total int)

Insert several rows of tests into the temporary table # tblDelete to demonstrate how to delete data

Insert into # tblDelete (Code, Total) values ('Code1', 30); insert into # tblDelete (Code, Total) values (' Code2', 40); insert into # tblDelete (Code, Total) values ('Code3', 50); insert into # tblDelete (Code, Total) values (' Code4', 6)

Query test data in temporary table # tblDelete

Select * from # tblDelete

Delete the record of Code field = Code3 in temporary table # tblDelete, using the following delete statement

Delete # tblDelete where Code = 'Code3'

If you query the result of temporary table # tblDelete again, you can see that the record of Code3 is gone.

Select * from # tblDelete

Delete the record in the Code field = Code2 in the temporary table # tblDelete, using the following delete statement.

Note that the following delete statement is followed by a from keyword, which can be omitted, but is not recommended

Delete from # tblDelete where Code = 'Code2'

If you query the result of temporary table # tblDelete again, you can see that the record of Code2 is gone.

Select * from # tblDelete

Finally, if you want to delete all the data in the table quickly, there are two ways. The second way is faster.

Delete from # tblDelete;truncate table # tblDelete

The above is all the content of the article "how to delete data using delete statement". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Data statement face query key keyword content again method article result test demonstration value usage interest partner suggestion method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Linux macOS Huawei