Lab Answer Key - Module 3 - Working With Databases and Storage
Lab Answer Key - Module 3 - Working With Databases and Storage
Lab: Managing Database Storage
Exercise 1: Configuring tempdb Storage
Task 1: Prepare the Lab Environment
1. Ensure that the 20462CMIADC and 20462CMIASQL virtual machines
and then log on to 20462CMIASQL as ADVENTUREWORKS\Student
password Pa$$w0rd.
2. In the D:\Labfiles\Lab03\Starter folder, rightclick Setup.cmd, and then
administrator.
3. Click Yes when prompted to confirm you want to run the command file,
script to finish.
Task 2: Configure tempdb Files
1. Start SQL Server Management Studio and connect to the MIASQL databa
using Windows authentication.
2. In Object Explorer, expand Databases, expand System Databases, rightc
and click Properties.
3. On the Files page, view the current file settings. Then click Cancel.
4. On the toolbar, click New Query.
5. Enter the following statements and click Execute alternatively, you can
Configure TempDB.sql script file in the D:\Labfiles\Lab03\Solution folder):
USE master;
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, SIZE = 10MB, FILEGROWTH =
= 'T:\tempdb.mdf');
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, SIZE=5MB, FILEGROWTH = 1MB,
'T:\templog.ldf');
GO
6. In Object Explorer, rightclick MIASQL and click Restart. When prompted
changes, to restart the service, and to stop the dependent SQL Server
Yes.
7. View the contents of T:\ and note that the tempdb.mdf and tempdb.ldf
moved to this location.
8. In SQL Server Management Studio, in Object Explorer, rightclick tempdb
Properties.
9. On the Files page, verify that the file settings have been modified. Then
10. Save the script file as Configure TempDB.sql in the D:\Labfiles\Lab03\Sta
11. Keep SQL Server Management Studio open for the next exercise.
Result: After this exercise, you should have inspected and configured the tempdb database.
Exercise 2: Creating Databases
Task 1: Create the HumanResources Database
1. In SQL Server management Studio, click New Query.
2. Enter the following statements and click Execute alternatively, you can
HumanResources.sql script file in the D:\Labfiles\Lab03\Solution folder)::
3. On Object Explorer, rightclick the Databases folder and click Refresh
HumanResources database has been created.
4. Save the script file as Create HumanResources.sql in the D:\Labfiles\Lab
folder.
Task 2: Create the InternetSales Database
1. In SQL Server management Studio, click New Query.
2. Enter the following statements and click Execute (alternatively, you can
InternetSales.sql script file in the D:\Labfiles\Lab03\Solution folder):
CREATE DATABASE InternetSales
ON PRIMARY
(NAME = 'InternetSales', FILENAME = 'M:\Data\InternetSales
= 5MB, FILEGROWTH = 1MB),
FILEGROUP SalesData
(NAME = 'InternetSales_data1', FILENAME =
'M:\Data\InternetSales_data1.ndf', SIZE = 100MB, FILEGROWT
(NAME = 'InternetSales_data2', FILENAME =
'N:\Data\InternetSales_data2.ndf', SIZE = 100MB, FILEGROWT
LOG ON
(NAME = 'InternetSales_log', FILENAME = 'L:\Logs\InternetS
SIZE = 2MB, FILEGROWTH = 10%);
GO
3. Under the existing code, enter the following statements. Then select the
have just added, and click Execute.
4. On Object Explorer, rightclick the Databases folder and click Refresh
InternetSales database has been created.
5. Save the script file as Create InternetSales.sql in the D:\Labfiles\Lab03\St
Task 3: View Data File Information
1. In SQL Server Management Studio, open the ViewFileInfo.sql script file
D:\Labfiles\Lab03\Starter folder.
2. Select the code under the comment View page usage and click Execute
retrieves data about the files in the InternetSales database.
3. Note the UsedPages and TotalPages values for the SalesData filegroup.
4. Select the code under the comment Create a table on the SalesData fileg
Execute.
5. Select the code under the comment Insert 10,000 rows and click Execute
6. Select the code under the comment View page usage again and click
7. Note the UsedPages value for the SalesData filegroup, and verify that
table is spread across the files in the filegroup.
Result: After this exercise, you should have created a new HumanResources database and
database that includes multiple filegroups.
Exercise 3: Attaching a Database
Task 1: Attach the AWDataWarehouse Database
1. Move AWDataWarehouse.ldf from the D:\Labfiles\Lab03\Starter\ folder
folder.
2. Move the following files from the D:\Labfiles\Lab03\Starter\ folder to the
o AWDataWarehouse.mdf
o AWDataWarehouse_archive.ndf
o AWDataWarehouse_current.ndf
3. In SQL Server Management Studio, in Object Explorer, rightclick Database
Attach.
4. In the Attach Databases dialog box, click Add. Then in the Locate Databa
box, select the M:\Data\AWDataWarehouse.mdf database file and click
5. In the Attach Databases dialog box, after you have added the master
that all of the database files are listed. Then click OK.
6. In Object Explorer, under Databases, verify that AWDataWarehouse is
Task 2: Configure Filegroups
1. In Object Explorer, rightclick the AWDataWarehouse database and click
2. On the Filegroups page, view the filegroups used by the database.
3. Select the ReadOnly checkbox for the Archive filegroup and click OK
4. In Object Explorer, expand AWDataWarehouse, and expand Tables. Then
dbo.FactInternetSales table and click Properties.
5. On the Storage page, verify that the dbo.FactInternetSales table is stored
filegroup. Then click Cancel.
6. Rightclick the dbo.FactInternetSalesArchive table and click Properties
7. On the Storage page, verify that the dbo.FactInternetSalesArchive table
Archive filegroup. Then click Cancel.
8. In Object Explorer, rightclick the dbo.FactInternetSales table and click
Rows.
9. Change the SalesAmount value for the first record to 2500 and press Ente
record. Then close the dbo.FactInternetSales table.
10. In Object Explorer, rightclick the dbo.FactInternetSalesArchive table
200 Rows.
11. Change the SalesAmount value for the first record to 3500 and press Ente
record.
12. View the error message that is displayed and click OK. Then press Esc
update and close the dbo.FactInternetSalesArchive table.
Result: After this exercise, you should have attached the AWDataWarehouse database to MIAS