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 Creating Tables and Manipulating Data with SQL Inserting, Updating and Deleting Rows

Aaron Munoz
Aaron Munoz
11,177 Points

Difference between a query and sql file.

I noticed that Andrew started insert data in a new sql file while I was doing it in a query tab. What's the difference? What's the purpose of each? Thanks!

2 Answers

Gareth Borcherds
Gareth Borcherds
9,372 Points

No real difference. Only thing would be that with a sql file you can save your sql queries and run them on different databases or keep your queries for later use. A lot of time I build them in the query tab in my sql tool and then save them in a sql file once they run correctly to use later.

A query is an operation on the database.

A sql file is a list of queries to run. If you want to run many queries back to back, you may want to store them all in a sql file so you don't have to wait for the responses on each. Similarly, if you dump your database into a backup, that will be stored as a sql file that you can call later to recreate that database. From time to time, you may install a software package that requires a database, and they may distribute a sql file to create that required database.