Question

As part of a clearout of our database, we want to delete all bookings from the cd.bookings table. How can we accomplish this?
Schema reminder
DB schema

Expected Results

bookid facid memid starttime slots

Your Answer Hint Help Save Run Query

 

Answers and Discussion Show

delete from cd.bookings;          

The DELETE statement does what it says on the tin: deletes rows from the table. Here, we show the command in its simplest form, with no qualifiers. In this case, it deletes everything from the table. Obviously, you should be careful with your deletes and make sure they're always limited - we'll see how to do that in the next exercise.

An alternative to unqualified DELETEs is the following:

truncate cd.bookings;

TRUNCATE also deletes everything in the table, but does so using a quicker underlying mechanism. It's not perfectly safe in all circumstances, though, so use judiciously. When in doubt, use DELETE.

Take a look at the DELETE statement in the PostgreSQL docs.

Keyboard shortcuts:


Other hints: