Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views2 pages

T SQL Lab Guide 09 10

The document outlines a lab exercise for writing basic SELECT statements in SQL using the ADVENTUREWORKS database. It provides step-by-step instructions for setting up the lab environment, viewing tables, and executing queries to retrieve data from the Sales.Customers table. The exercise aims to teach users how to create simple SELECT statements to analyze existing tables.

Uploaded by

Arif Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

T SQL Lab Guide 09 10

The document outlines a lab exercise for writing basic SELECT statements in SQL using the ADVENTUREWORKS database. It provides step-by-step instructions for setting up the lab environment, viewing tables, and executing queries to retrieve data from the Sales.Customers table. The exercise aims to teach users how to create simple SELECT statements to analyze existing tables.

Uploaded by

Arif Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MCT USE ONLY.

STUDENT USE PROHIBITED


L3-1

Module 3: Writing SELECT Queries


Lab: Writing Basic SELECT Statements
Exercise 1: Writing Simple SELECT Statements
 Task 1: Prepare the Lab Environment
Ensure that the MT17B-WS2016-NAT, 20761C-MIA-DC and 20761C-MIA-SQL virtual machines are
both running, and then log on to 20761C-MIA-SQL as ADVENTUREWORKS\Student with the password
Pa55w.rd.

1. In the D:\Labfiles\Lab03\Starter folder, right-click Setup.cmd, and then click Run as


administrator.

2. In the User Account Control dialog box, click Yes.

3. When the script has finished, press Enter.

 Task 2: View All the Tables in the ADVENTUREWORKS Database in Object Explorer
1. On the taskbar, click Microsoft SQL Server Management Studio.
2. In the Connect to Server dialog box, in the Server name box, type MIA-SQL, and then click
Options.

3. Under Connection Properties, in the Connect to database list, click <Browse server>.

4. In the Browse for Databases dialog box, click Yes.

5. In the Browse Server for Databases dialog box, under User Databases, click TSQL, and then click
OK.

6. In the Connect to Server dialog box, on the Login tab, in the Authentication list, click Windows
Authentication, and then click Connect.

7. In Object Explorer, under MIA-SQL, expand Databases, expand TSQL, and then expand Tables.
8. Under Tables, notice that there are four table objects in the Sales schema:

 Sales.Customers

 Sales.OrderDetails

 Sales.Orders

 Sales.Shippers

 Task 3: Write a Simple SELECT Statement That Returns All Rows and Columns from a
Table
1. On the File menu, point to Open, and then click Project/Solution.
2. In the Open Project dialog box, navigate to the D:\Labfiles\Lab03\Starter\Project folder, and then
double-click Project.ssmssln.

3. In Solution Explorer, expand Queries, and then double-click Lab Exercise 1.sql.

4. In the query window, highlight the statement USE TSQL;, and then click Execute.
MCT USE ONLY. STUDENT USE PROHIBITED
L3-2 Querying Data with Transact-SQL

5. In the query pane, after the Task 2 description, type the following query:

SELECT *
FROM Sales.Customers;

6. Highlight the query you typed, and click Execute.

7. In the query pane, type the following code after the first query:

SELECT *
FROM

8. In Object Explorer, under MIA-SQL, under Databases, under TSQL, under Tables, click
Sales.Customers.

9. Drag the selected table into the query pane, after the FROM clause. Add a semicolon to the end of
the SELECT statement. Your finished query should look like this:

SELECT *
FROM [Sales].[Customers];

10. Highlight the written query, and click Execute.

 Task 4: Write a SELECT Statement That Returns Specific Columns


1. In Object Explorer, expand Sales.Customers, expand Columns and observe all the columns in the
Sales.Customers table.

2. In the query pane, after the Task 3 description, type the following query:

SELECT contactname, address, postalcode, city, country


FROM Sales.Customers;

3. Highlight the written query, and click Execute.


4. Observe the result. How many rows are affected by the last query? There are multiple ways to answer
this question using SQL Server Management Studio. One way is to select the previous query and click
Execute. The total number of rows affected by the executed query is written in the Results pane
under the Messages tab:

(91 row(s) affected)

Another way is to look at the status bar displayed below the Results pane. On the left side of the status
bar, there is a message stating: “Query executed successfully.” On the right side, the total number of rows
affected by the current query is displayed (91 rows).

Results: After this exercise, you should know how to create simple SELECT statements to analyze existing
tables.

You might also like