This session includes the following topics: Detaching and attaching a database Best practices Slide 1 Installing Windows XP Professional Using Attended Installation Slide 1 of 16 Ve
Trang 1Instructor Inputs S e
Trang 3This session includes the following topics:
Detaching and attaching a database
Best practices
Slide 1
Installing Windows XP Professional Using Attended Installation
Slide 1 of 16
Ver 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 7
Objectives
In this session, you will learn about:
Detaching and attaching a database Restore operation
Best practices that can be considered while managing databases and database objects using SQL Server 2005 Tips and tricks will help you to effectively manage database and database objects using SQL Server 2005
FAQs related to database files and filegroups of SQL Server 2005
Trang 4Slide 2 of 16
Knowledge Byte
Detaching a database is the same as logically removing the database from the SQL Server
A SQL Server 2005 database can be detached by using:
SQL Server Management Studio T-SQL
To move a database from an instance of SQL Server, you can detach it from one instance and attach it to another instance.
You can attach a database by using:
SQL Server Management Studio T-SQL
The process of retrieving data from a backup and applying transaction log to the data is called as restoring.
Slide 3
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Knowledge Byte (Contd.)
The process of rolling forward uncommitted transactions, if any, and bringing the database online is known as recovery
In a restore process, the logged changes are applied to the data in a database to retrieve the data on time This process
is known as rolling forward and the set of data restored is known as roll forward set
Each restore scenario is implemented by using one or more restore steps (operations), called a restore sequence
A restore operation is a multiphase process The possible phases of a restore process are:
Data copy phase Redo phase Undo phase
Trang 5Slide 4 of 16
Best Practices
While creating your own database objects, ensure that you
do not create the database objects in the system databases like master database
While moving master database and log files to another location, ensure that you also move the Resource database
to the same location.
While restoring the Resource database you must be careful not to overwrite the current Resource database with an out-of-date or potentially insecure version of Resource database
Slide 5
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Best Practices (Contd.)
The size of tempdb can affect the performance of a system
If the size of the tempdb is less than the requirement of the server, it would have an impact on the performance of the server A good practice is to increase the size of tempdb.
It is not a good idea to shrink a database if the database has frequent updations In these cases, shrinking a database is
a wasted operation
Trang 6Slide 6 of 16
Tips and Tricks
Backup the master database after performing the following operations:
Creating, modifying, or dropping a database Changing server and database configuration values Modifying or adding logon accounts
After restoring a backup of mssqlsystemresource.mdf, it is a good practice to reapply any subsequent updates
After you add or delete files in a database, create a database backup immediately
If you have to create multiple secondary files in your database, create them in a separate filegroup
Do not put the Resource database in either compressed or encrypted NTFS file system folders
Slide 7
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Can you change the owner of the master database?
You cannot change the owner of master database as it is owned by dbo.
FAQs
Trang 7Slide 8 of 16
Can master database be dropped?
No, you cannot drop master database as it is a system database.
FAQs (Contd.)
Slide 9
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
While creating objects in a database if user does not specify the filegroup, which filegroup are objects assigned to?
The objects are by default assigned to default filegroup The primary filegroup is the default filegroup.
FAQs (Contd.)
Trang 8Slide 10 of 16
What are the three types of files used to store a database?
Which of these files are must for a database?
The three types of files to store a database are primary files, secondary files, and transaction files A database must have a primary file and atleast one transaction log file.
FAQs (Contd.)
Slide 11
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Can transaction log files be a part of any filegroup?
No, transaction log file are never a part of any filegroup
FAQs (Contd.)
Trang 9Slide 12 of 16
Challenge
Which of the following statement is NOT correct about detaching a database?
It’s a logical removal of database from the server
A detached database can be attached to a SQL Server in the same computer
Using the SQL Server Management Studio you can detach a database
A detached database cannot be attached to SQL Server of another computer
Answer:
A detached database cannot be attached to SQL Server
of another computer
Slide 13
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Challenge (Contd.)
Which T-SQL procedure is used to detach a database?
sp_detach_db sp_detach sp_db_detach sp_detachdb
Answer:
sp_detach_db
Trang 10Slide 14 of 16
Challenge (Contd.)
Which of the following statement will detach the AdventureWorks and execute the UPDATE STATISTIC process?
sp_detach_db 'AdventureWorks', 'TRUE' sp_detach_db 'AdventureWorks', ‘NULL’
sp_detach 'AdventureWorks', 'TRUE' sp_detach 'AdventureWorks', 'NULL'
Answer:
sp_detach_db 'AdventureWorks', ‘NULL’
Slide 15
Installing Windows XP Professional Using Attended Installation Querying, Managing, and Administering Databases Using SQL Server 2005
Challenge (Contd.)
In which condition CREATE DATABASE with FOR ATTACH clause is used?
When the database is detached using sp_detach_db statement
When the database is detached using SQL Server Management Studio
When the number of data files to be attached is more than 16 When the database needs to be attached to a server on a different computer
Answer:
When the number of data files to be attached is more than 16
Trang 11Slide 16 of 16
Challenge (Contd.)
Which phase of restore process is skipped if the data is already transactionally consistent at the start of the recovery process?
Redo Phase Data Copy Phase Undo Phase Roll Forward Phase
Answer:
Undo Phase
Trang 121 d A detached database cannot be attached to SQL Server of another computer
4 c When the number of data files to be attached is more than 16
5 c Undo Phase
Trang 131 Which of the following statement is true about log files?
a These file are used to recover a database
b These files have an extension of ndf
c A database can have only one log file
d The minimum size of log files is 256 MB
2 Which of the following commands will remove the filegroup fg1 from the database
db1?
3 Which of the following commands will show the information for the emp_sts
statistics on the Event table?
c sp_helpstats ('db1.Event', emp_sts)
d sp_helpstats 'db1.Event', ‘emp_sts’
4 Which of the following command checks for the consistency of disk space allocation
structures for a particular database?
5 Which of the following is NOT a schedule type available in the New Job Schedule
dialog box?
a Recurring
b First time
c Start automatically when SQL Server Agent starts
Trang 14b Database scope
Server login?
9 Which of the following fixed database role allows adding, modifying, and dropping database objects?
10 Which of the following is a database level permission?
Solutions
1 These file are used to recover a database
5 First time
Trang 15After SQL Server installation and database and database objects creation, you as a
database administrator need to decide on the security of the data and database server
Security means restricting access to data and database server by granting and denying
access to database and its objects to the right person at right time
Discuss the basic components of SQL Server that are used in implementing security such
as users and logins
Instructor Inputs
You can conduct the discussion as follows:
Discuss the principals, securables, and permissions to secure data and database
server
Also discuss role of encryption in securing data
Solution
To secure a database server the SQL server provides the different components to apply
security at different levels In addition the data and messages in server can also be
encrypted to provide security
Using SQL Server components to secure the database server
The SQL Server provides a set of components, such as principals, securables, and
permissions, which can be used to apply security at different levels
Principals
Principals are logical entities that need to access the resources of the SQL Server These
entities include computer accounts, logins, and user accounts used to access the data in
the database Principals can be given permission to access an object, such as tables or
Trang 16following levels:
Permissions
You can allow or disallow principals to access the securables by setting permissions Permissions govern the level of access that principals have on the securables Depending
on the role, different users can perform different actions on the database
Using encryption to secure data and messages
In addition to restricting access to database and database objects, you can add one more layer of security by encrypting data You can encrypt data and complete database objects, such as procedures or functions, by using keys and certificates A key is a value that can
be applied to a cryptographic function to encrypt or decrypt a secure data value
A digitally signed certificate ensures that the message should not be intercepted and read
by third party It also ensures that the message is not tampered or the sender’s identity altered
After creating the keys and certificates, you can use keys and certificates to encrypt data and implement security You can encrypt the data stored in a table or you can save a function or stored procedure in an encrypted format