Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Daniel Fitzhugh
Daniel Fitzhugh
9,715 Points

When you IMPORT a file into the database, should you DELETE what is already there first ?

Let's assume that you are managing a single Wordpress website, and you have a single database which contains all of the information for that one website. Nothing else is in this database, and you just want to overwrite the existing data with the new data.

When you import a new .SQL file into the database, should you delete what is already there first ? Or will the file that you import successfully overwrite everything that needs to be overwritten, in a similar way to what FTP does, for example ?

Hope this question makes sense :)

1 Answer

Adam Pengh
Adam Pengh
29,880 Points

Depends on how the SQL file was generated. Typically, if you export a database to a SQL file, there will be a statement to drop the existing table and then another statement to create the table again. I would check the SQL file to see if those statements exists. If they don't and the only thing that is in the SQL file are SQL statements to insert data, then those records will be added to what is already there.

Standard practice is to drop the existing table and then create a new table with the same name and insert the records.

Daniel Fitzhugh
Daniel Fitzhugh
9,715 Points

Thanks Adam, that's very clear :)