MS SQL Server Concepts and Programming Question: Download Questions PDF
How To Delete an Existing Row with DELETE Statements in MS SQL Server?
![MS SQL Server Interview Answer MS SQL Server Interview Question](https://globalguideline.com/public/images/interview/13.png)
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.
-- 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 Interview Questions And Answers
PDF
Previous Question | Next 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? |