Home> Database> SQL> body text

How to delete data using delete statement

藏色散人
Release: 2020-05-26 10:49:07
Original
16389 people have browsed it

How to delete data using delete statement

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 );
Copy after login

How to delete data using delete statement

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);
Copy after login

How to delete data using delete statement

Query the temporary table#tblDelete Test data in

select * from #tblDelete;
Copy after login
Copy after login
Copy after login

How to delete data using delete statement

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

delete #tblDelete where Code = 'Code3'
Copy after login

How to delete data using delete statement

Query the temporary table again#tblDelete results, you can see that the record of Code3 is gone

select * from #tblDelete;
Copy after login
Copy after login
Copy after login

How to delete data using delete statement

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'
Copy after login

How to delete data using delete statement

Query temporarily again As a result of table #tblDelete, you can see that the record of Code2 is gone

select * from #tblDelete;
Copy after login
Copy after login
Copy after login

How to delete data using delete statement

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;
Copy after login

How to delete data using delete statement

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!