MS SQL Server Concepts and Programming Question: Download MS SQL Server PDF

How To Delete an Existing Row with DELETE Statements in MS SQL Server?

Tweet Share WhatsApp

Answer:

If you want to delete an existing row from a table, you can use the DELETE statement with a WHERE clause to identify that row. Here is good sample of DELETE statements:

-- insert a row for this test
INSERT INTO ggl_links (url, id)
VALUES ('www.google.com', 301)
GO
(1 row(s) affected)

-- view the inserted row
SELECT id, url, notes, counts FROM ggl_links
WHERE id = 301
GO
id url notes counts
301 www.google.com NULL NULL

-- delete one row
DELETE FROM ggl_links WHERE id = 301
GO
(1 row(s) affected)

-- try to view the deleted row
SELECT id, url, notes, counts FROM ggl_links
WHERE id = 301
no rows

Row with id of 301 is truly deleted.

Download MS SQL Server PDF Read All 394 MS SQL Server Questions
Previous QuestionNext Question
What Happens If the UPDATE Subquery Returns Multiple Rows in MS SQL Server?How To Delete Multiple Rows with One DELETE Statement in MS SQL Server?