Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Database Foundations Manipulating Schema with SQL Altering Tables

Sean Flanagan
Sean Flanagan
33,235 Points

DELETE vs DROP vs TRUNCATE

Hi.

So have I got this right? DELETE deletes one table row, TRUNCATE deletes every row in a table, and DROP deletes the entire table?

Thanks in advance.

Sean

1 Answer

Steven Parker
Steven Parker
231,269 Points

Close. You're right about TRUNCATE and DROP. Now DELETE can remove a single row, it can also delete every row. For example:

DELETE FROM mytable WHERE id = 21;

...would remove just one row (assuming id is a unique key and there is a row with 21 in it). But just this:

DELETE FROM mytable;

...would remove every row. By using different WHERE conditions you could also delete more than one, but not all rows.