简体   繁体   中英

How do I delete data using the primary key in SQL Server?

Working on a small database project, and one of the requirements is to show how to delete data using the primary key. The exact statement is

  • Show one delete statement that use a primary key to delete data

However, I can't figure out what the exact syntax for that would be. Could anyone show me a quick example?

That's a basic delete statement . Assuming table mytable and primary key id :

delete from mytable where id = 1

Use the WHERE clause In the delete statement to specify the conditions used to limit the number of rows that are deleted. For example, WHERE column_name = value. If a WHERE clause is not supplied, DELETE removes all the rows from the table.

DELETE FROM table_name WHERE condition;

for example:

table name= person

enter image description here

DELETE FROM persons WHERE id > 3;

deleted items which had id>3 and return me:

enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM