Escolar Documentos
Profissional Documentos
Cultura Documentos
1-15
The purpose of this practice is to enable you to create a database by using SQL Server
Management Studio and by using Transact-SQL. In this practice, you will use both
techniques to create a new database.
Objectives
In this practice, you will:
Instructions
Log on to the virtual machine with the user name Student and the password
Pa$$w0rd.
Value
Server type
Database Engine
Server name
MIAMI
Authentication
Windows Authentication
1-16
3. If Object Explorer is not visible, on the View menu, click Object Explorer.
4. In Object Explorer, right-click Databases, and then click New Database.
5. In the New Database dialog box, specify the details in the following table.
Property
Value
Database name
TestDB
20
6. In the Autogrowth column of the TestDB entry, click the ellipsis button (...).
7. In the Change Autogrowth for TestDB dialog box, clear the Enable Autogrowth
check box, and then click OK.
8. For the TestDB_log entry, change the Initial Size setting to 5 MB.
9. In the Autogrowth column of the TestDB_log entry, click the ellipsis button (...).
10. In the Change Autogrowth for TestDB_log dialog box, clear the Enable
Autogrowth check box, and then click OK.
11. In the New Database dialog box, click OK to create the database.
12. In Object Explorer, expand the Databases folder to verify that TestDB has been
created. If TestDB is not listed, right-click the Databases folder, and then click
Refresh.
13. Keep SQL Server Management Studio open. You will use it in the next procedure.
1-23
The purpose of this practice is to enable you to create filegroups by using SQL Server
Management Studio and by using Transact-SQL. In this practice, you will use both
techniques to create a new database filegroup.
Objectives
In this practice, you will:
Instructions
Ensure that you are logged on to the virtual machine with the user name Student and
the password Pa$$w0rd.
1-24
Property
Value
Server type
Database Engine
Server name
MIAMI
Authentication
Windows Authentication
3. If Object Explorer is not visible, on the View menu, click Object Explorer.
4. In Object Explorer, expand Databases, right-click TestDB, and then click
Properties.
5. In the Database Properties - TestDB dialog box, in the Select a page pane, click
Filegroups, and then click Add.
6. Enter the settings in the following table.
Property
Value or action
Name
SECONDARY
Default
Selected
7. In the Select a page pane, click Files, and then click Add.
8. Type in the settings in the following table.
Property
Value
Logical Name
TestDB2
File Type
Data
Filegroup
SECONDARY
9. In the Database Properties - TestDB dialog box, click OK to create the new file and
filegroup.
10. In Object Explorer, if the TestDB node is not selected, click TestDB.
11. On the Summary tab, click Report.
12. When the report is displayed, expand Disk Space Used by Data Files. The report
should show the two filegroups and the list of files for each group.
13. Keep SQL Server Management Studio open. You will use it in the next procedure.
1-25
TO FILEGROUP [SECONDARY]
GO
ALTER DATABASE [TransactTestDB] MODIFY FILEGROUP [SECONDARY] DEFAULT
GO
1-31
The purpose of this practice is to enable you to create schemas by using SQL Server
Management Studio and by using Transact-SQL. In this practice, you will use both
techniques to create a new schema.
Objectives
In this practice, you will:
Instructions
Ensure that you are logged on to the virtual machine with the user name Student and
the password Pa$$w0rd.
Important: This demonstration requires you to have completed the first practice in
this module, "Creating Databases."
1-32
Property
Value
Server type
Database Engine
Server name
MIAMI
Authentication
Windows Authentication
3. If Object Explorer is not visible, on the View menu, click Object Explorer.
4. In Object Explorer, expand Databases, expand TestDB, expand Security, right-click
Schemas, and then click New Schema.
5. In the Schema - New dialog box, in the Schema name box, type Sales, and then
click OK.
6. In Object Explorer, expand Schemas, and then confirm that the Sales schema exists.
7. Keep SQL Server Management Studio open. You will use it in the next procedure.
1-39
Create a schema.
Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the
lab, you must:
Log on to the virtual machine with the user name Student and the password
Pa$$w0rd.
Lab Scenario
The senior database developer at Adventure Works has created a specification for a new
database in which details of the information technology (IT) assets used by the company
will be stored. You must use the specification to create the appropriate filegroups, create
the database with the necessary options, create the required schemas, and create a
database snapshot.
The senior database developer has provided you with the following requirements for the
new database:
1-40
The database should consist of two data files and one log file with the names
AW_IT_Assets_Data1, AW_IT_Assets_Data2, and AW_IT_Assets_log. These
files should be created in the C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\Data folder.
The database should use two filegroups, the primary filegroup and a filegroup named
SECONDARY, which should be the default filegroup. The AW_IT_Assets_Data2
file should be placed in the SECONDARY filegroup.
Both data files should have an initial size of 20 megabytes (MB) each and should not
grow automatically. The log file should have an initial size of 5 MB and should not
grow automatically.
The database should automatically close when no users are connected and should
automatically shrink when appropriate.
A script for creating and populating a table has been generated and must be executed
in the database.
The user MIAMI\Katie should use the TechSupport schema as her default schema.
The files for the database snapshot must be created in the C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ folder.
Use SQL Server Management Studio to create scripts for each action, and then save
these scripts in a SQL Server Scripts project in the D:\Labfiles\Starter folder. This
project can be used to document the database configuration and to re-create the
database if necessary.
Scripts to create tables and users have been provided in the D:\Labfiles\Starter folder.
Additional Information
When performing database development tasks, it can be helpful to use SQL Server
Management Studio to create a SQL Server Scripts project, and use it to document the
Transact-SQL code necessary to re-create the solution if necessary.
Use the following procedure to create a SQL Server Scripts project:
1. Open SQL Server Management Studio, connecting to the server you want to manage.
2. On the File menu, point to New, and then click Project.
3. Select the SQL Server Scripts template and enter a suitable name and location for
the project. Note that you can create a solution that contains multiple projects, but in
many cases a single project per solution is appropriate.
1-41
1-42
Tasks
Supporting information
1.
2.
filegroups.
1-43
Verify that the user can select information from the Asset table only by qualifying
the table name with the schema.
Change the default schemas for the users, and retest access to the table within the
default schema.
Tasks
Supporting information
1.
Add a new query to the project and connect to the MIAMI instance by
using Windows authentication.
Execute the script to create the Asset table and the login for
MIAMI\Katie.
2.
3.
4.
Rewrite the query to use the two-part name for the table and execute
the query.
1-44
Tasks
default schema.
Supporting information
In a Command Prompt window, run sqlcmd, and then write TransactSQL statements to select all the data from the Asset table without
specifying the schema name. Notice that now the table is displayed
correctly.