DELETE TOP command in SQL Server
The DELETE TOP command in SQL Server is used to delete records from a table in SQL and limits the number of records based on an existing value or percentage.
The DELETE TOP command in SQL Server is used to delete records from a table in SQL and limits the number of records based on an existing value or percentage.
DELETE TOP command syntax
DELETETOP (giatri_dau) [PERCENT]
FROM bang
[WHERE dieu
_kien];
Variable name or variable value
state
Table wants to delete records from there.
WHERE dieu_kien
Option. The condition that the record must meet to be deleted.
TOP (giatri_dau)
This command will delete the first row in the result set based on giatri_dau. For example, TOP (10) will delete the top 10 that meet the criteria.
PERCENT
Option. If specified, the first rows are based on the percentage of giatri_dau of the result set. For example, TOP (10) PERCENT will insert 10% of the first value in the result set.
Note
There is no need to list all fields in the DELETE statement because it will delete all rows in the table.
For example - use the keyword TOP
DELETE TOP(10)
FROM nhanvien
WHERE ho
= 'Anderson';
In this example, the DELETE TOP command will delete the first 10 records in the table with the employee family, Anderson. If there are other records that also have the family name of Anderson, they will not be deleted.
For example - use the keyword TOP PERCENT
DELETE TOP (25) PERCENT
FROM nhanvien
WHERE ten = 'Sarah';
In this example, 25% of the DELETE TOP response's delete records will be deleted. The remaining 75% will not be deleted.
Previous article: SELECT INTO command in SQL Server
The following article: UNION operator in SQL Server
You should read it
- DELETE command in SQL Server
- DISTINCT clause in SQL Server
- VIEW in SQL Server
- Foreign Key with Cascade Delete in SQL Server
- Delete the foreign key in SQL Server
- The TRUNCATE TABLE command in SQL Server
- The difference between Truncate and Delete in Microsoft SQL Server
- How to delete the database in MS SQL Server
- DROP USER command in SQL Server
- FUNCTION (Function) in SQL Server
- SELECT TOP command in SQL Server
- How to decentralize users in MS SQL Server
Maybe you are interested
What is success? See 12 definitions of the success of the most successful people in the world! 7 habits every Monday morning of successful people 10 drinks before going to bed help reduce belly fat quickly Discover the strange green planet HD 189733b outside the solar system The biggest super moon in 70 years will appear on November 14 20 pictures of super beautiful splendor around the world on November 14