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).
Video: SQL Query Tutorial & Tips
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).



Thank you for all the instructions, tips, videos, etc. I am taking a daring step from MS Access toward SQL Server 2008. I am familiar with Oracle SQL Developer tool. Now, I would like to know if there is a way in T-SQL to accomplish the “&” prompt that is used in Oracle SQL. For example. I would like to type any known field from table “Table1″ by:
Select [type a fieldcolumn here when prompted]
From Table1
go
Any help is greatly appreciated. Thank you.
Thanks for the question. I don’t believe there is an equivalent feature in SQL Server that will prompt the user for input. However, you could create a stored procedure that takes a parameter and uses that parameter to modify the query called. Or you could use the SQLCMD utility with variables that you pass to accomplish the same thing in a script (see http://msdn.microsoft.com/en-us/library/ms188714.aspx). In both cases, your user would have to call the procedure or script with the desired variable to change the output (rather than being prompted). To get more complicated, you could create a .BAT file or a PowerShell file or a console application that prompts the user and then either runs code or spawns the SQLCMD utility to run the query using the user input. Sorry that none of these are exactly the same solution.
Oh boy, am i glad i ended up on this site!!!!
I`m a network administrator and really find sql very interesting, i only have experience in database backups and restoring.
I downloaded these videos, and so many things are making sense now, i`m watching the videos and studying the sql book as well, just wanted to THANK Jason for the great work and effort you put in!
I will stay in touch,
Jaco