The exercises for this chapter and Chapter 4 provide numbered, step-by-step instructions. The solutions for these exercises are the final query, commands, or result. The exercises for subsequent chapters provide less-detailed instructions. You should use the material in each chapter to determine the appropriate steps and to find the solutions.
|
|
|
Answers
| The SQL Expression in the third pane of the graphical query designer should be as follows: SELECT TOP 100 PERCENT ProductID, Name, ListPrice FROM dbo.Product ORDER BY Name |
|
|
|
Answers
| The SQL expression in the third pane of the graphical query designer should be as follows (formatting may vary):
SELECT TOP 100 PERCENT dbo.ProductSubCategory.Name AS SubCategory, dbo.Product.Name AS ProductName, dbo.Product.ListPrice FROM dbo.Product INNER JOIN dbo.ProductSubCategory ON dbo.Product.ProductSubCategoryID = dbo.ProductSubCategory.ProductSubCategoryID ORDER BY dbo.ProductSubCategory.Name, dbo.Product.Name |
| Write a simple query using the query editor window in Query Analyzer or the SQL Server Manager Studio using the following steps:
|
|
Answers
| This query returns 58 rows. These are all of the products with a list price greater then $4,000. |
| Execute a simple query using command-line utilities:
|
|
Answers
| Command-line statements should resemble the following: > OSQL –E (or SQLCMD –E) > USE AdventureWorks2000 > GO > SELECT ProductCategoryID, Name FROM ProductCategory > GO > EXIT > EXIT For simple Transact-SQL commands, the OSQL and SQLCMD command-line query utilities are nearly identical. The SQLCMD tool supports additional enhancements for SQL Server 2005. The –E switch indicates that the database query engine should open a new connection using Windows Integrated, or Enterprise, security; using the current user's Windows credentials. The session will be opened using the default database, typically the Master database, so it is necessary to explicitly name the target database for this session. Commands are executed in batch mode, and no commands are actually processed until a batch directive statement (GO) is issued. The first EXIT command is processed by the query utility, which exits the session, closes the connection, and returns control to the command shell prompt. The second EXIT statement is processed by the command shell. This closes the command prompt window and terminates the command session. |