Get startedGet started for free

Deleting data and dropping table

Besides being able to CREATE, INSERT, or UPDATE, it is also important to know how to DELETE and DROP a table. With DELETE, it is possible to delete a certain line of the table and with DROP TABLE, it is possible to erase the entire table and its definition.

The syntax for both operators is as follows.

Delete the line where lineID = 1 from the Employee table:

DELETE FROM Employee 
WHERE lineID = 1;

Drop the entire Employee table:

DROP TABLE Employee

Your task is to delete some lines of the previously defined Person table and finally, to drop the entire table.

This exercise is part of the course

Hierarchical and Recursive Queries in SQL Server

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

INSERT INTO Person 
VALUES (1,'Andrew','Anderson','Adress 1','City 1','1986-12-30');
INSERT INTO Person 
VALUES (2,'Peter','Jackson','Adress 2','City 2','1986-12-30');
INSERT INTO Person 
VALUES (5,'Michaela','James','Adress 3','City 3','1976-03-07');

-- Delete the record for the person with the ID of 1
___ FROM ___ 
WHERE ___ = ___;
-- Delete the record with the name Jackson
___ FROM ___ 
___ ___ = 'Jackson';

SELECT * 
FROM Person;
Edit and Run Code