Jobsheet 2
Jobsheet 2
files can be used to spread data across multiple disks by putting each file on a different disk
drive. Additionally, if a database exceeds the maximum size for a single Windows file, you can
use secondary data files so the database can continue to grow. The recommended extension for
secondary data files is .ndf.
some time later, during a background process known as a "checkpoint" process, the dirty pages
are written to the database files. For this reason, the pages that are contained in the transaction
log are critical to the ability of SQL Server to recover the database to a known committed state.
Transaction logs are discussed in detail in later modules in this course.
2.3 Recovery
While disk subsystems are increasing in reliability, failures do still occur. If a SQL
Server data file is lost, the database could be restored from a backup and the transaction log
reapplied to recover the database to a recent point in time. If a SQL Server log file is lost, the
database can be forced to recover from the data files, with the possibility of some data loss or
inconsistency in the database. But if both the data and log files are on a single disk subsystem
that is lost, the recovery options usually involve restoring the database from an earlier backup
and losing all transactions since that time. Isolating data and log files can help to avoid the
worst impacts of drive subsystem failures.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
A number of management advantages are gained from allocating multiple data files:
• The main management advantage gained from allocating multiple data files is the
possibility of moving files and part of the data later.
• Another management advantage gained through the use of multiple data files is that if
a database file is being restored separately, the recovery time can be minimized. This
could be useful where only part of the data was corrupt.
• Splitting a database across multiple data files can increase the parallelism in the I/O
channel.
• The final advantage is that if a database exceeds the maximum size for a single
Windows file, you can
need for SQL Server to ever autogrow the files. Instead, you should monitor file growth over
time and ensure that files are large enough for many months or years.
Many administrators are concerned that larger database files will somehow increase the
time it takes to perform backups. The size of a SQL Server backup is not related directly to the
size of the database files. Only used portions of the database are backed up.
One significant issue that arises with autogrowth is that there is a tradeoff related to the
size of the growth increments. If a large increment is specified, a significant delay can be
experienced in the execution of the T-SQL statement that triggered the need for growth. If a
too small increment is specified, the filesystem can become very fragmented and the database
performance can suffer because the data files have been allocated in small chunks all over a
disk subsystem.
master
The master database contains all system-wide information. Anything that is defined at the
server instance level is typically stored in the master database. If the master database is
damaged or corrupted, SQL Server will not start, so it is very important to backup the master
database on a regular basis.
msdb
The msdb database holds information for the SQL Server Agent. Jobs, operators, and alerts
which are stored in the msdb database. It is also important to perform a backup of the msdb
database regularly, to ensure that jobs, schedules, and history for backups, restores, and
maintenance plans are not lost. In earlier versions of SQL Server, SQL Server Integration
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
Services (SSIS) packages were often stored within the msdb database also. In SQL Server
2012, these should be stored in the dedicated SSIS database instead.
model
The model database is the template on which all user databases are based. Any new database
that is created uses the model database as a template. Any objects created in the model database
will be present in all new databases that are created on the server instance. Many sites do not
ever modify the model database. Note that even though the model database does not seem
overly important, SQL Server will not start if the model database is not present.
tempdb
The tempdb database holds temporary data. This database is truncated or created every time
that SQL Server starts so there is no need to perform a backup on this database. In fact, there
is no option to perform a backup of the tempdb database. The tempdb database is discussed
further in the next topic.
resource
The resource database is a read-only hidden database that contains system objects that are
mapped to the sys schema in every database. This database also holds all system stored
procedures, system views and system functions. In SQL Server versions before SQL Server
2005 these objects were defined in the master database.
5. Overview of tempdb
5.1 Key Points
The tempdb database consists of the internal objects, the row version store and user
objects. The performance of the tempdb database is critical to the overall performance of most
SQL Server installations.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
1. Click Start, click All Programs, click Microsoft SQL Server 2012, click SQL Server
Management Studio. In the Connect to Server window, type Proseware and click
Connect. From the File menu, click Open, click Project/Solution, navigate to
10775A_04_PRJ.ssmssln and click Open.
2. From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql
script file from within Solution Explorer.
3. Open the 11 – Demonstration 1A.sql script file.
4. Follow the instructions contained within the comments of the script file.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
CREATE DATABASE
Database names must be unique within an instance of SQL Server and comply with the
rules for identifiers. A database name is of data type "sysname" which is currently defined as
nvarchar(128). This means that up to 128 characters can be present in the database name and
that each of the characters can be chosen from the double-byte Unicode character set. While
database names can be quite long, you will find that long names become awkward to work
with.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
9. Altering Databases
9.1 Key Points
When databases are in operation, they may need to be modified. The most common
requirement is to add additional space by either expanding existing files or by adding additional
files.
ALTER DATABASE
Expanding files and adding files can both be done through the ALTER DATABASE
statement or via the GUI in SSMS. Another option that you might need to implement is to drop
a file. SQL Server will not allow you to drop a file that is currently in use within the database.
Dropping a file has to be done in two steps. First the file has to be emptied using the
EMPTYFILE option of DBCC SHRINKFILE and then it can be removed using the ALTER
DATABASE command.
be considered a rarely used option. Both data and transaction log files can be reduced, or
shrunk. The database files can be shrunk manually, either as a group or individually, or the
database can be set to shrink automatically at specified intervals.
Demo 4 : Filegroups
1. If Demo 2was not performed:
• Click Start, click All Programs, click Microsoft SQL Server 2012, click SQL Server
Management Studio. In the Connect to Server window, type Proseware and click
Connect. From the File menu, click Open, click Project/Solution, navigate to
10775A_04_PRJ.ssmssln and click Open.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql
script file from within Solution Explorer.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
UPDATE STATISTICS
SQL Server maintains a set of statistics on the distribution of data within tables and
indexes. As part of the detach process, an option is provided to perform an UPDATE
STATISTICS operation on table and index statistics prior to the detach. While this might be
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
The process of moving user database files requires the use of the logical names of the
database files. You can see the logical names of existing files by executing the following code:
The use of detach and attach for moving user database files across instances will be
shown in the next demonstration.
2. In the SQL Server Services node, right-click the instance of SQL Server and choose
Properties and click the Startup Parameters tab.
3. Edit the Startup Parameters values to point to the planned location for the master database
data (-d parameter) and log (-l parameter) files.
4. Stop the instance of SQL Server.
5. Move the master.mdf and mastlog.ldf files to the new location.
6. Restart the instance of SQL Server.
1. For each file to be moved, execute ALTER DATABASE ... MODIFY FILE as for
user databases.
2. Stop the instance of SQL Server.
3. Move the files to the new location.
4. Restart the instance of SQL Server.
In the next demonstration, you will see how to move the tempdb database and how to
increase the number of files that it is using.
The main disadvantage of detaching and attaching and backup and restore is that only
the database is copied and the DBA needs to take care of all dependent objects like logins, jobs,
user-defined error messages and so on.
Restoring a database on another instance has the advantage that backups should be
created regularly anyway and can therefore be restored easily without affecting the source
system. Performing the restoration is itself a good test of the current backup strategy. Also the
source database stays online during the whole operation. Restoring a database also has the issue
related to recovering dependent objects.
• Open the 10775A_04_PRJ SQL Server script project within SQL Server Management
Studio.
• From the View menu, click Solution Explorer. Open and execute the 00 – Setup.sql
script file from within Solution Explorer.
EXERCISE
Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the lab,
you must complete the following steps:
1. Click Start, click All Programs, click Microsoft SQL Server 2012, and click SQL
Server Management Studio.
2. In the Connect to Server window, type Proseware in the Server name text box.
3. In the Authentication drop-down list box, select Windows Authentication and click
Connect.
4. In the File menu, click Open, and click Project/Solution.
5. In the Open Project window, open the project 10775A_04_PRJ.ssmssln.
6. From the View menu, click Solution Explorer. In Solution Explorer, double-click the
query 00-Setup.sql. When the query window opens, click Execute on the toolbar.
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
Lab Scenario
Now that the Proseware instance of SQL Server has been installed and configured on the
server, a number of additional database configurations need to be performed. As the database
administrator, you need to perform these configuration changes.
You need to create a new database on the server, based on requirements from an application
vendor’s specifications. A client has sent you a database that needs to be installed on the
Proseware instance. Instead of sending you a backup, they have sent a detached database and
log file. You need to attach the database to the Proseware instance.
A consultant has also provided recommendations regarding tempdb configuration that you
need to review and implement if appropriate
Item Requirement
DatabaseName RateTracking
Primary Data File Logical name = RateTracking_dat
File name = RateTracking.mdf
Folder = D:\MKTG
Initial size = 10MB
Maximum file size = 100MB
Autogrowth amount = 10MB
Filegroup = PRIMARY
Log File Logical name = RateTracking_log
File name = RateTracking.ldf
Folder = L:\MKTG
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
Item Requirement
Initial size = 20MB
Maximum file size = unlimited
Autogrowth amount = 20MB
Filegroup = Not Applicable
Secondary Data File Logical name =
#1 RateTracking_dat_1
File name = RateTracking_1.ndf
Folder = D:\MKTG
Initial size = 20MB
Maximum file size = 100MB
Autogrowth amount = 10MB
Filegroup = USERDATA
Secondary Data File #2 Logical name =
RateTracking_dat_2
File name = RateTracking_2.ndf
Folder = D:\MKTG
Initial size = 20MB
Maximum file size = 100MB
Autogrowth amount = 10MB
Filegroup = USERDATA
Secondary Data File Logical name =
#3 RateTracking_dat_3
File name = RateTracking_3.ndf
Folder = D:\MKTG
Initial size = 200MB
Maximum file size = 500MB
Autogrowth amount = 50MB
Filegroup = ARCHIVE
Secondary Data File #4 Logical name =
RateTracking_dat_4
File name = RateTracking_4.ndf
Folder = D:\MKTG
Initial size = 200MB
Maximum file size = 500MB
Autogrowth amount = 50MB
Filegroup = ARCHIVE
Default Filegroup USERDATA
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
Filename Requirements
Secondary Data File Logical name = tempdev2
#1 File name =
tempdb_file2.ndf
Folder = D:\MKTG
Initial size = 20MB
Maximum file size =
unlimited
Autogrowth amount =
10MB
Secondary Data File Logical name = tempdev3
#2 File name =
tempdb_file3.ndf
Folder = D:\MKTG
Initial size = 20MB
Maximum file size =
unlimited
Autogrowth amount =
10MB
Secondary Data File Logical name = tempdev4
#3 File name =
tempdb_file4.ndf
Folder = D:\MKTG
Initial size = 20MB
Maximum file size =
unlimited
Autogrowth amount =
10MB
Jurusan Teknologi Informasi Politeknik Negeri Malang
Jobsheet-1: File and Filegoups
Mata Kuliah Sistem Manajemen Basis Data
(International)
Pengampu: Tim Ajar Sistem Manajemen Basis Data
Febuari 2020
Scenario
You will adjust the current configuration of the tempdb database. The main tasks for this
exercise are as follows:
• Restart the Proseware server using SQL Server Configuration Manager. • Check that
tempdb is still the correct size.
Results: After this exercise, you should have inspected and configured the tempdb
database.
Scenario
You will create a new database named RateTracking as per a supplied set of specifications.
The main tasks for this exercise are as follows:
Results: After this exercise, you should have created a new RateTracking database with
multiple filegroups.
Scenario
A client has sent you a database that needs to be installed on the Proseware instance. Instead
of sending you a backup, they have sent a detached database and log file. You need to attach
the database to the Proseware instance.
• Task 2: Attach the database to the MKTG instance • Attach the OldProspects
database to the MKTG instance.
Results: After this exercise, you should have attached a database to a client’s server.