0% found this document useful (0 votes)
594 views7 pages

Module 1 Lab: Creating A Database

1. The document provides step-by-step instructions for creating a SQL Server database, schemas, and snapshot. It instructs how to create the database with two filegroups, add schemas, create a table and login, and test data access. 2. Next, it details how to create a database snapshot of the original database on the file system. Testing shows the snapshot contains the original data while the live database is updated. 3. Disk usage of the snapshot files increases, demonstrating the snapshot captured the original data.

Uploaded by

kossuth atilla
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)
594 views7 pages

Module 1 Lab: Creating A Database

1. The document provides step-by-step instructions for creating a SQL Server database, schemas, and snapshot. It instructs how to create the database with two filegroups, add schemas, create a table and login, and test data access. 2. Next, it details how to create a database snapshot of the original database on the file system. Testing shows the snapshot contains the original data while the live database is updated. 3. Disk usage of the snapshot files increases, demonstrating the snapshot captured the original data.

Uploaded by

kossuth atilla
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/ 7

Module 1 Lab: Creating a Database

Exercise 1: Creating a Database


Lab answer key

Creating a SQL Server Management Studio Scripts project


You must perform the following steps to create the database with appropriate options and
filegroups:

1. Click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click
SQL Server Management Studio.
2. In the Connect to Server dialog box, specify the values in the following table, and then click
Connect.
Property Value
Server type Database Engine
Server name MIAMI
Authentication Windows Authentication

3. On the File menu, point to New, and then click Project.


4. In the New Project dialog box, specify the values in the following table, and then click OK.
Property Value
Name AW_IT_Database
Location D:\Labfiles\Starter
Create directory for Unselected
solution

5. On the Project menu, click New Query. Connect to MIAMI by using Windows
authentication when prompted.
6. If Solution Explorer is not visible, click Solution Explorer on the View menu.
7. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file to
CreateAW_IT_Assets.sql.
Creating the new database with appropriate options and filegroups
You must perform the following steps to create the new database with appropriate
options and filegroups:

1. If Object Explorer is not visible, click Object Explorer on the View menu.
2. In Object Explorer, right-click Databases, and then click New Database.
3. In the New Database dialog box, type AW_IT_Assets as the Database name.
4. For the first database file, modify the details to match those in the following table.
Property Value
Logical Name AW_IT_Assets_Data1
File Type Data
Filegroup PRIMARY
Initial Size (MB) 20

5. In the Autogrowth column of the AW_IT_Assets_Data1 entry, click the ellipsis button (…).
6. In the Change Autogrowth for AW_IT_Assets_Data1 dialog box, clear the Enable
Autogrowth check box, and then click OK.
7. Click Add to create a new data file.
8. For the new database file, enter the details in the following table.
Property Value
Logical Name AW_IT_Assets_Data2
File Type Data
Initial Size (MB) 20

9. In the Autogrowth column of the AW_IT_Assets_Data2 entry, click the ellipsis button (…).
10. In the Change Autogrowth for AW_IT_Assets_Data2 dialog box, clear the Enable
Autogrowth check box, and then click OK.
11. In the Filegroup column for the AW_IT_Assets_Data2 file, click <new filegroup> in the
drop-down list.
12. In the New Filegroup for AW_IT_Assets dialog box, enter the details in the following table,
and then click OK.
Property Value
Name Secondary
Options - Default Select the check box

13. Change the Initial Size setting for the AW_IT_Assets_log entry to 5.
14. In the Autogrowth column of the AW_IT_Assets_log entry, click the ellipsis button (…).
15. In the Change Autogrowth for AW_IT_Assets_log dialog box, clear the Enable
Autogrowth check box, and then click OK.
16. In the New Database dialog box, click the Script drop-down arrow on the toolbar, and then
click Script Action to Clipboard.
17. Click OK to create the new database.
18. Click in the CreateAW_IT_Assets.sql window to ensure it is active, and on the Edit menu,
click Paste.
19. On the File menu, click Save All.
20. Do not close SQL Server Management Studio; you will use it in the next exercise.
Exercise 2: Creating Schemas

Lab answer key

Creating the schema


You must perform the following steps to create the schema:

1. Return to SQL Server Management Studio.


2. On the Project menu, click New Query. Ensure that the connection settings are correct, and
then click Connect.
3. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file to
CreateAW_IT_Schemas.sql.
4. In Object Explorer, expand Databases, AW_IT_Assets, Security, right-click Schemas, and
then click New Schema.
5. In the Schema – New dialog box, type TechSupport as the Schema name, but do not click
OK yet.
6. Click the Script drop-down arrow, and then click Script Action to Clipboard.
7. Click OK to create the schema.
8. Right-click in the CreateAW_IT_Schemas.sql query window, and click Paste.
9. On the File menu, click Save All.

Creating the new table and login


You must perform the following steps to create the new table and login:

1. On the Project menu, click Add Existing Item.


2. Locate the D:\Labfiles\Starter\Create_AW_IT_Table_and_User.sql file, and then click
Add. When prompted, connect to MIAMI.
3. Click the Execute button on the toolbar to create the new Asset table and the login for
MIAMI\Katie.

Testing data access


You must perform the following steps to test data access:

1. Click Start, and then click Run.


2. Enter runas /noprofile /user:MIAMI\Katie cmd.
3. When prompted for the user password, enter Pa$$w0rd. This creates a new command prompt
window that is running as the MIAMI\Katie user account.
4. In the new command prompt window, enter sqlcmd -S MIAMI -E. This starts the SQL
Server 2005 command prompt, which allows you to execute statements against a database.
5. Enter the following code. (sqlcmd will insert line numbers automatically.)

USE AW_IT_Assets
SELECT * FROM Asset
GO

An error message is displayed within the command prompt window because the dbo schema does
not contain the Asset table.
6. Enter the following code.

USE AW_IT_Assets
SELECT * FROM TechSupport.Asset
GO

Three records are displayed within the command prompt window because the statement includes
the schema.
7. Do not close the command prompt window.

Changing the default schema for the user


You must perform the following steps to change the default schema for the user:

1. Return to SQL Server Management Studio.


2. In Object Explorer, expand Databases, AW_IT_Assets, Security, Users, right-click
MIAMI\Katie, and then click Properties.
3. In the Database User – MIAMI\Katie dialog box, type TechSupport for Default schema,
but do not click OK yet.
4. Click the Script drop-down arrow, and then click Script Action to Clipboard.
5. Click OK to change the default schema for MIAMI\Katie.
6. Right-click in the CreateAW_IT_Schemas.sql query window under the existing script, and
click Paste.
7. On the File menu, click Save All.
8. Return to the command prompt window that is running sqlcmd.
9. Enter the following code.

USE AW_IT_Assets
SELECT * FROM Asset
GO

Three records are displayed within the command prompt window because the default schema for
MIAMI\Katie is now TechSupport.
10. Type Exit to close the sqlcmd connection and close the command prompt window.
11. Keep SQL Server Management Studio open; you will use it in the next exercise.
Exercise 3: Creating a Database Snapshot

Lab answer key

Creating a database snapshot


You must perform the following steps to create a database snapshot:

1. In SQL Server Management Studio, on the Project menu, click New Query. Connect to
MIAMI by using Windows authentication when prompted.
2. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file to
CreateAW_IT_Snapshot.sql.
3. In the new, blank query window, type the following Transact-SQL code.

CREATE DATABASE AW_IT_Assets_Snapshot1 ON


( NAME = 'AW_IT_Assets_Data1', FILENAME =
N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AWIT1.ss'),
( NAME = N'AW_IT_Assets_Data2', FILENAME =
N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AWIT2.ss')
AS SNAPSHOT OF AW_IT_Assets

4. On the File menu, click Save All.


5. Click the Execute button on the toolbar.
6. In Object Explorer, expand Databases, Database Snapshots, and then confirm that the new
database snapshot exists. You might need to refresh the list of database snapshots before the
new snapshot becomes visible.
7. Click Start, and then click Windows Explorer.
8. Open the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data folder.
9. Right-click AWIT2.ss, and then click Properties. Note the current Size on disk value. Click
OK, but leave Windows Explorer open.
10. Return to SQL Server Management Studio, and then click the New Query button on the
toolbar.
11. In the new, blank query window, type the following Transact-SQL code.

INSERT AW_IT_Assets.TechSupport.Asset (Description, Location)


VALUES ('Workstation 2', 'Meeting Room 1')

SELECT *
FROM AW_IT_Assets.TechSupport.Asset

SELECT *
FROM AW_IT_Assets_Snapshot1.TechSupport.Asset
12. Click the Execute button on the toolbar, and view the results. Notice that the first result set
contains four records and the second contains only three records, as expected.
13. Return to Windows Explorer.
14. Right-click AWIT2.ss, and then click Properties. Notice that the new Size on disk value is
different from the previous value. Click OK, and then close Windows Explorer.
15. Close SQL Server Management Studio.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy