This next video in the Learning SQL Server video series looks at getting started with Transact-SQL (T-SQL) queries in SQL Server. A query is just a question about your data. T-SQL is just the language used to ask that question. This video looks at basic SELECT queries and then moves on to concepts of aggregations and joins. In the process, it provides tips working with queries in SQL Server Management Studio (SSMS).
Note that this video uses an example database, ExperimentData, that was first introduced in the “What is a Relational Database?” video. You can run the queries in this video by running a database script to create this sample database. Copy the script from this page and run it in a new query window in SQL Server Management Studio. You have to be connected to your database instance and have permissions to create databses. I could have made this a backup file or .MDF file, but the script makes it more likely that anyone can use this simple database, because you could run it in SQL server 2005, 2008, or 2008 R2.
Couple of tips to reiterate from the video:
- I use F5 to run queries rather than the toolbar. Easy and fast.
- Highlight portions of the query window to run just that highlighted section.
- For complex queries, add one thing at a time and test each change. This is much easier than trying to write several lines of a complex query all at once.
- Take advantage of the documentation. Search for “Transact-SQL site:msdn.microsoft.com” and then add the keyword you’re interested in, such as “SELECT”. For example, here are the bing search results for this example. Note that the examples in the documentation are often the place that help new users the most.
For more tips and links, see the “Transact-SQL” section of the post: How to Learn SQL Server Online (Advice & Resources).