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!
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
Andrew Walters8,876 Points
Drop if exists
Hey there guys! I'm curious, why would someone want to drop some (database/table/col/etc) using the key if it exists? What are the benefits to doing this? Having no experience in building databases, it doesn't really make sense to me to delete say a table if it doesn't exist in the first place.
Ken AlgerTreehouse Teacher
You will get errors if you ask it to drop a table which does not exist. Therefore it is a best practice to do a
DROP TABLE IF EXISTS to prevent errors. It is also a frequently asked question in job interviews, in my experience. Same with the opposite end of the idea,
CREATE TABLE IF NOT EXISTS, which prevents table duplication.