SQL Server
SQL Server
L1-1
Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008
L1-2
4. 5.
The Lesson 1: Basic Navigation in SQL Server Management Studio page opens in the right pane. In the Contents pane, expand Lesson 1: Basic Navigation in SQL Server Management Studio, and then click the topic Connecting with Registered Servers and Object Explorer. The content of the page opens in the right pane.
6.
Task 3: Resize, hide, and close Object Explorer and Solution Explorer
1. 2. 3. 4. 5. 6. Reduce the size of the Contents pane by resizing it. Scroll down the Connecting with Registered Servers and Object Explorer page to view its contents. Click the Close button to close the Help window. On the View menu, click Solution Explorer. In Solution Explorer, click Auto Hide to hide the pane. In Object Explorer, click Auto Hide to hide the pane.
Task 4: Create a new solution and explore the solution objects in Object Explorer
1. 2. 3. 4. 5. 6. 7. 8. 9. Open Object Explorer by clicking the Object Explorer tab. In Object Explorer, click Auto Hide to dock the pane. In the Object Explorer, double-click the Databases folder, double-click AdventureWorks2008, and then double-click Tables. You can scroll through the pane to view the list of tables. On the toolbar, click New Query. The SQLQuery1.sql - NY-SQL01.AdventureWorks2008 window opens. Open Solution Explorer by clicking the Solution Explorer tab. In Solution Explorer, click Auto Hide to dock the pane. In Solution Explorer, right-click Solution 'Solution1' (1 project), point to Add, and then click New Project. The Add New Project dialog box appears.
L1-3
10. In the Templates box, verify that the SQL Server Scripts template is highlighted. 11. In the Name field, select SQL Server Scripts1, type PersonAddress, and then click OK. 12. The PersonAddress project will be created under Solution Solution1 (1 project). 13. In Solution Explorer, in the PersonAddress project, right-click Connections, and then click New Connection. 14. The Connect to Server dialog box appears. Verify the connection information, and then click OK.
Task 5: Add projects to an existing solution and create queries in the projects
1. 2. 3. 4. 5. 6. 7. 8. 9. In the Connections folder of the PersonAddress project, right-click NY-SQL01:NY-SQL-01\Student, and then click New Query. The SQLQuery1.sql object appears in the Queries folder. In the query window, type USE AdventureWorks2008, and then press ENTER. On the toolbar, click Execute. The active database is changed to AdventureWorks2008. In the query window, type SELECT DISTINCT CITY FROM Person.Address. On the toolbar, click Execute. The list of cities in the Person.Address table is displayed without repetition in the Results pane. In the Queries folder of PersonAddress project, right-click SQLQuery1.sql, and then click Rename.
10. Rename the query as Address.sql. 11. The query has been renamed to Address.sql. 12. On the File menu, click Save Address.sql. 13. In Solution Explorer, right-click PersonAddress, and then click Save PersonAddress.ssmssqlproj.
L1-4
14. Right-click Solution Solution1 (1 project), point to Add, and then click New Project. 15. The Add New Project dialog box appears. 16. In the Templates box, verify that the SQL Server Scripts template is highlighted. 17. In the Name field, select SQL Server Scripts1, type HumanResourcesDepartment, and then click OK. 18. The HumanResourcesDepartment project is created under Solution Solution1 (2 projects). 19. In the HumanResourceDepartments project, right-click Connections, and then click New Connection. 20. The Connect to Server dialog box appears. 21. Verify the connection information, and then click OK. 22. In the Connections folder, under HumanResourceDepartments, right-click NY-SQL-01:NY-SQL-01\Student and then click New Query. 23. The SQLQuery1.sql folder appears. 24. In the Queries folder of HumanResourcesDepartment project, right-click SQLQuery1.sql, and then click Rename. 25. Rename the query as Department.sql. 26. The query has been renamed to Department.sql. 27. In the query window, type USE AdventureWorks2008, and then press ENTER. 28. On the toolbar, click Execute. 29. The active database is changed to AdventureWorks2008. 30. In the query window, type SELECT Name, GroupName FROM HumanResources.Department. 31. On the toolbar, click Execute. 32. The Name and GroupName columns are displayed in the Results pane. 33. On the File menu, and click Save Department.sql. 34. In Solution Explorer, right-click the HumanResourcesDepartment project, and then click Save HumanResourcesDepartment.ssmssqlproj.
L1-5
35. Click Solution Solution1 (2 projects). 36. On the File menu, click Save Solution1 As. 37. The Save File As dialog box appears. Verify that the Projects folder is selected in the Save in: list. 38. In the File name field, type AdventureWorks2008.ssmssln, and then click Save. 39. Click the Close button to close SQL Server Management Studio.
4. 5. 6. 7. 8.
L1-6
10. In the Query Designer dialog box, click OK. 11. Notice the query in the SQLQuery1.sql - NY-SQL-01.AdventureWorks2008 query pane. 12. On the toolbar, click Execute. 13. All the columns in the Person.Address table are displayed in the Results pane. 14. Click the Close button to close SQL Server Management Studio. 15. The Microsoft SQL Server Management Studio dialog box appears. 16. Click No to close the solution without saving changes.
Results: After this exercise, you should have explored the components and executed queries in the SQL Server Management Studio.
L1-7
5.
Task 3: Run a Transact-SQL script file and save the output to a text file
1. In the Command Prompt window, type: sqlcmd -S NY-SQL-01 -i E:\MOD01\Labfiles\Starter\Department.sql -o E:\MOD01\Labfiles\Solution\DeptList.txt. Press ENTER. Notice that there is no output in the Command Prompt window.
2. 3.
L1-8
4. In the details pane, double-click DeptList.txt. 5. 6. 7. 8. 9. The DeptList.txt - Notepad window opens. Notice that the results are similar to the results returned in the earlier task. Close Notepad. Close Windows Explorer. Close Command Prompt.
Results: After this exercise, you should have started and used sqlcmd to create reports.
L1-9
Exercise 3: Generate a report from a SQL Server database using Microsoft Office Excel
Task 1: Launch Excel
1. 2. On the Start menu, click All Programs, click Microsoft Office, and then click Microsoft Office Excel 2007. The Microsoft Excel window opens.
L1-10