Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Written by Andrew Gould
In this tutorial
This tutorial teaches you how to write the most basic of SQL queries and will introduce you to some good habits that are worth getting into early on in your query-writing career. If you haven't already done so, now is the time to open SQL Server Management Studio and get ready to start querying.
Before you can start writing a query you need to create a new query window. There are several ways to do this, but whichever method you choose it makes sense to select the database on which you'll be running the query first:
Use the Object Explorer window to select the database you want to use. Here we've clicked on the name of the Movies database.
Once you've selected the database you can create a query window in one of several ways:
Click the New Query button on the toolbar.
Look for this button at the top left of the screen.
From the menu choose: File > New > Query with Current Connection.
Choose this option to create a new query window.
Right-click on the database and choose New Query.
Right-click on the database you want to use and select the option shown here.
Press CTRL + N on the keyboard.
Whichever method you choose you should see a new query window appear with a flashing text cursor in the top left corner.
You should also see the name of the selected database in the drop down list on the toolbar.
You can use comments to explain what your query does to other users, or even yourself when you come back to look at your code later. You can add a comment to any line in your query by typing in two dashes, as shown below:
After typing in two dashes you can start typing your comment.
You can also add comments over multiple lines, as shown in the diagram below:
Use /* symbols to start a multi-line comment and */ symbols to end it.
Although it takes time, adding comments to your SQL code is a good idea, especially when you're first learning the language.
You can learn more about this topic on the following Wise Owl courses:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.