How to use delete statement to delete data?
Create a temporary table to demonstrate the use of delete in sqlserver syntax
Recommended: "SQL Tutorial"
IF OBJECT_ID('tempdb..#tblDelete') IS NOT NULL DROP TABLE #tblDelete; CREATE TABLE #tblDelete( Code varchar(50), Total int );
Insert a few test rows 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 the temporary table#tblDelete Test data in
select * from #tblDelete;
Delete the record with Code field = Code3 in temporary table #tblDelete, use the following delete statement
delete #tblDelete where Code = 'Code3'
Query the temporary table again#tblDelete results, you can see that the record of Code3 is gone
select * from #tblDelete;
Delete the temporary table#tblDelete in the Code field =Code2 To record, use the delete statement below.
Note that there is a from keyword after the delete statement below. This keyword can be omitted, but it is recommended not to omit it
delete from #tblDelete where Code = 'Code2'
Query temporarily again As a result of table #tblDelete, you can see that the record of Code2 is gone
select * from #tblDelete;
Finally, if you want to quickly delete all the data in the table, there are two ways below. The second way is faster
delete from #tblDelete; truncate table #tblDelete;
The above is the detailed content of How to delete data using delete statement. For more information, please follow other related articles on the PHP Chinese website!