From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Change database context with USE

Change database context with USE - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

Change database context with USE

- [Instructor] I think writing queries against a database can be a fun process of diving into the data tables and seeing what kinds of useful insights you can reveal. Queries can get rather long, though, especially when you're joining multiple tables together, performing calculations, and grouping rows to get the final output. So after you've spent a bunch of time crafting the perfect query, it would be a sensible thing to want to save that text of a query to a script. That way, you could easily run it again at a later date, or share it with colleagues to allow them to benefit from all of your hard work. Before you do that, though, there are a couple of enhancements that you can make to your query to make sure that anyone who runs it has a good experience with it. Let's suppose this simple SELECT statement is a masterpiece of query design. When you execute the query, it goes into the database and retrieves the…

Contents