Answers to Exercises: Simple SELECT Queries

Here are the answers to the questions from the lesson on Simple SELECT Queries.

Question 1

How can you find all the table names in the AdventureWorks2012 database?

 The easiest way, when starting out with Microsoft SQL server, is to use SQL Server Management Studio’s object explorer to open and explore a database’s tables.

Object Explorer Tables

Question 2

What are two ways to get the names of all the columns in the Person.Person table?

The first way is to use the object explorer.  Below is a picture on how to do this.

Object Explorer Columns

The second way is to use the following SQL statement:

SELECT * FROM Person.Person

Note:  Though SELECT * will give you all the columns, I wouldn’t advise using it on a large database!

Question 3

Select JobTitle and BirthDate for all employees.

SELECT JobTitle,
FROM   HumanResources.Employee

Question 4

What would the UnitPrice of each PurchaseOrderDetail items be if there was a half off sale?

SELECT PurchaseOrderID,
       UnitPrice / 2 as HalfOff
From   Purchasing.PurchaseOrderDetail
  • Anita Kegler says:

    Hi Kris,

    I am VERY new to SQL and this was my first lesson. I have been putting it off because I thought it would be so difficult. Increasingly I am seeing the need for it in the future for my job. I found your lesson to be incredibly interesting and well put together in a way that is easy for me to understand. Just wanted to say thank you! I signed up for your emails some time ago and have saved them all and am itching now to DIVE into all of them!

    Happy New Year!
    Anita Kegler
    Albuquerque, New Mexico

  • Kennacho says:

    Indeed this was helpful. I ve been trying to really understanding basic querying but been having difficulties. After reading this I ve gotten a clearly picture of how it works,meaning of some commands. Thanks a lot for this material made available to us. I hope to get better and better

  • Naga says:

    Hi Kris,
    I really enjoyed this lesson, Thanks much!
    To answer your 1st question, can we write a query – SELECT * FROM sys.tables ?
    Let me know if this is correct or not.

  • >