WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 519 reviews for our classroom and online training
Basic SQL Queries
Part one of a five-part series of blogs

This blog teaches the absolute basics of writing queries in Microsoft SQL Server Management Studio. You'll learn how to use the SELECT and FROM keywords to create simple queries showing all of the records from a single table.

  1. Getting Started with SQL Queries (this blog)
  2. Referring to Tables in the FROM Clause
  3. Adding Columns to the SELECT List
  4. Executing SQL Queries
  5. Useful Hints for Writing Basic Queries

This blog is part of our complete SQL tutorial.  Alternatively, have a look at our SQL training courses for small groups.

Posted by Andrew Gould on 23 July 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Getting Started with SQL Queries

This blog 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.

Creating a New Query Window

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:

Selecting database

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.
New query

Look for this button at the top left of the screen.

  • From the menu choose: File > New > Query with Current Connection.
Using menu

Choose this option to create a new query window.

  • Right-click on the database and choose New Query.
Right-clicking database

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.

New query window

You should also see the name of the selected database in the drop down list on the toolbar.

Adding Comments to a Query

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:

Adding a comment

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:

Multi line comments

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.

What's Next?

Now that you have a query window with a basic comment you can start writing the actual query!  Read the next part of this blog to find out what to write.

This blog has 0 threads Add post