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

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

T SQL Lab Guide 07 08

The document outlines a series of exercises for executing T-SQL scripts, focusing on uncommenting code to set the database context and executing queries. It emphasizes the importance of understanding database context and how to sort data using the ORDER BY clause. The exercises aim to teach users how to manipulate comments in T-SQL scripts and observe the results of their queries.

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)
4 views2 pages

T SQL Lab Guide 07 08

The document outlines a series of exercises for executing T-SQL scripts, focusing on uncommenting code to set the database context and executing queries. It emphasizes the importance of understanding database context and how to sort data using the ORDER BY clause. The exercises aim to teach users how to manipulate comments in T-SQL scripts and observe the results of their queries.

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


L2-3

3. By deleting these two characters, you have removed the comment mark. Now the line will not be
ignored by SQL Server.
4. On the File menu, click Save 61 - Lab Exercise 2.sql.

5. In the Save File As dialog box, click Save.

6. In the Confirm Save As dialog box, click Yes

7. On the File menu, click Close. This will close the T-SQL script.

8. In Solution Explorer, double-click 61 - Lab Exercise 2.sql.

9. Click Execute.
10. Observe the results. Why did the script execute with no errors? The script now includes the
uncommented USE TSQL; statement. When you execute the whole T-SQL script, the USE statement
sets the database context to the TSQL database. The next statement in the T-SQL script, the SELECT,
then executes against the TSQL database.

11. On the File menu, click Close.

Results: After this exercise, you should have a basic understanding of database context and how to
change it.

Exercise 3: Executing Queries That Sort Data Using ORDER BY


 Task 1: Execute the Initial T-SQL Script
1. In Solution Explorer, double-click 71 - Lab Exercise 3.sql.

2. Click Execute.
3. Notice that the result window is empty. All the statements inside the T-SQL script are commented
out, so SQL Server ignores them.

 Task 2: Uncomment the Needed T-SQL Statements and Execute Them


1. Locate the line:

--USE TSQL;

2. Delete the two characters before the USE statement. The line should now look like this:

USE TSQL;

3. Locate the block comment start element /* after the Task 1 description and delete it.
4. Locate the block comment end element */ and delete it.
Any text residing within a block starting with /* and ending with */ is treated as a block comment and
is ignored by SQL Server.

5. Highlight the statement:

USE TSQL;

6. Click Execute. The database context is now set to the TSQL database.
MCT USE ONLY. STUDENT USE PROHIBITED
L2-4 Querying Data with Transact-SQL

7. Highlight the statement:

SELECT
firstname, lastname, city, country
FROM HR.Employees
WHERE country = 'USA'
ORDER BY lastname;

8. Click Execute.

9. Observe the result and notice that the rows are sorted by the lastname column in ascending order.

Results: After this exercise, you should have an understanding of how comments can be specified inside
T-SQL scripts. You will also have an appreciation of how to order the results of a query.

You might also like