Codd's Rules for a Truly Relational Database System
1. Information is represented logically in tables.
2. Data must be logically accessible by table, primary key, and column.
3. Null values must be uniformly treated as "missing information," not as empty strings, blanks, or zeros.
4. Metadata (data about the database) must be stored in the database just as regular data is.
5. A single language must be able to define data, views, integrity constraints, authorization, transactions, and data manipulation.
6. Views must show the updates of their base tables and vice versa.
7. A single operation must be able to retrieve, insert, update, or delete data.
8. Batch and end user operations are logically separate from physical storage and access methods.
9. Batch and end user operations can change the database schema without having to re-create it or applications built upon it.
10. Integrity constraints must be available and stored in the metadata, not in an application program.
11. The data manipulation language of the relational system should not care where or how the physical data is distributed and should not require alteration if the physical data is centralized or distributed.
12. Any row processing done in the system must obey the same integrity rules and constraints that set-processing operations do.
Monday, March 17, 2008
Thursday, March 13, 2008
Redundancy methods
Hot Standby
A method of redundancy in which the primary and secondary (i.e., backup) systems run simultaneously. The data is mirrored to the secondary server in real time so that both systems contain identical information.
Warm Standby
A method of redundancy in which the secondary (i.e., backup) system runs in the background of the primary system. Data is mirrored to the secondary server at regular intervals, which means that there are times when both servers do not contain the exact same data.
Cold Standby
A method of redundancy in which the secondary (i.e., backup) system is only called upon when the primary system fails. The system on cold standby receives scheduled data backups, but less frequently than a warm standby. Cold standby systems are used for non-critical applications or in cases where data is changed infrequently.
A method of redundancy in which the primary and secondary (i.e., backup) systems run simultaneously. The data is mirrored to the secondary server in real time so that both systems contain identical information.
Warm Standby
A method of redundancy in which the secondary (i.e., backup) system runs in the background of the primary system. Data is mirrored to the secondary server at regular intervals, which means that there are times when both servers do not contain the exact same data.
Cold Standby
A method of redundancy in which the secondary (i.e., backup) system is only called upon when the primary system fails. The system on cold standby receives scheduled data backups, but less frequently than a warm standby. Cold standby systems are used for non-critical applications or in cases where data is changed infrequently.
Thursday, February 14, 2008
Wednesday, February 13, 2008
Recovery models
Simple Recovery Model
This recovery model facilitates the maintenance of a database by making the transaction log virtually maintenance free. There are limitations placed on the recoverability of a database if this recovery model is used.
Bulk-Logged Recovery Model
A database in this recovery model will have minimum logging for bulk import operations. Space allocation and deallocation is only logged for bulk import operations. Point-in-time and point-of-failure recovery may be possible when a database is in Bulk-Logged Recovery model.
Full Recovery Model
SQL Server performs full transaction logging for any bulk load operations if a database is in Full Recovery model. Transaction log backups should be performed at regular intervals for maximum recoverability. This model provides the safest mode of operation for production systems.

Complete/Full - Backs up the entire database.
Differential - Backs up only modified extents since the previous complete backup.
Transaction Log - Backs up the active portion and truncates the inactive portion of the transaction log.
File / Filegroup - Backs up individual files and filegroups within a database.
This recovery model facilitates the maintenance of a database by making the transaction log virtually maintenance free. There are limitations placed on the recoverability of a database if this recovery model is used.
Bulk-Logged Recovery Model
A database in this recovery model will have minimum logging for bulk import operations. Space allocation and deallocation is only logged for bulk import operations. Point-in-time and point-of-failure recovery may be possible when a database is in Bulk-Logged Recovery model.
Full Recovery Model
SQL Server performs full transaction logging for any bulk load operations if a database is in Full Recovery model. Transaction log backups should be performed at regular intervals for maximum recoverability. This model provides the safest mode of operation for production systems.

Complete/Full - Backs up the entire database.
Differential - Backs up only modified extents since the previous complete backup.
Transaction Log - Backs up the active portion and truncates the inactive portion of the transaction log.
File / Filegroup - Backs up individual files and filegroups within a database.
T-SQL and DB tales
create database a
on
(
name = 'a_data',
filename = 'C:\a.mdf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB, --Unlimited
filegrowth = 2
)
Log on
(
name = 'a_log',
filename = 'C:\a.ldf',
size = 1MB,
maxsize = 5,
filegrowth = 2
)
create database b
on
(
name = 'b_data',
filename = 'C:\b.mdf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
),
filegroup new
(
name = 'b_data2',
filename = 'C:\b.ndf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
)
Log on
(
name = 'b_log',
filename = 'C:\b.ldf',
size = 1MB,
maxsize = 5,
filegrowth = 2
)
backup database b to disk = 'C:\b.bak'
restore database c from disk = 'C:\b.bak'
with
move 'b_data' to 'C:\c.mdf',
move 'b_data2' to 'C:\c.ndf',
move 'b_log' to 'C:\c.ldf'
alter database c add filegroup new2
alter database c
add file
(
name = 'c_data3',
filename = 'C:\c3.ndf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
) to filegroup new2
backup database a to disk = 'c:\a.bak' with differential
restore database b from disk = 'c:\a.bak' with file = 1, norecovery,
move 'a_data' to 'D:\Data\b.mdf',
move 'a_log' to 'E:\Log\b.ldf'
restore database b from disk = 'c:\a.bak' with file = 2, norecovery,
move 'a_data' to 'D:\Data\b.mdf',
move 'a_log' to 'E:\Log\b.ldf'
restore database b with recovery
on
(
name = 'a_data',
filename = 'C:\a.mdf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB, --Unlimited
filegrowth = 2
)
Log on
(
name = 'a_log',
filename = 'C:\a.ldf',
size = 1MB,
maxsize = 5,
filegrowth = 2
)
create database b
on
(
name = 'b_data',
filename = 'C:\b.mdf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
),
filegroup new
(
name = 'b_data2',
filename = 'C:\b.ndf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
)
Log on
(
name = 'b_log',
filename = 'C:\b.ldf',
size = 1MB,
maxsize = 5,
filegrowth = 2
)
backup database b to disk = 'C:\b.bak'
restore database c from disk = 'C:\b.bak'
with
move 'b_data' to 'C:\c.mdf',
move 'b_data2' to 'C:\c.ndf',
move 'b_log' to 'C:\c.ldf'
alter database c add filegroup new2
alter database c
add file
(
name = 'c_data3',
filename = 'C:\c3.ndf',
size = 2MB, --all default sizes are in MB
maxsize = 10MB,
filegrowth = 2
) to filegroup new2
backup database a to disk = 'c:\a.bak' with differential
restore database b from disk = 'c:\a.bak' with file = 1, norecovery,
move 'a_data' to 'D:\Data\b.mdf',
move 'a_log' to 'E:\Log\b.ldf'
restore database b from disk = 'c:\a.bak' with file = 2, norecovery,
move 'a_data' to 'D:\Data\b.mdf',
move 'a_log' to 'E:\Log\b.ldf'
restore database b with recovery
Server Startup parameters
Default parameters
-d master_file_path
The fully qualified path for the master database file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\master.mdf). If you do not provide this option, the existing registry parameters are used.
-e error_log_path
The fully qualified path for the error log file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG). If you do not provide this option, the existing registry parameters are used.
-l master_log_path
The fully qualified path for the master database log file (typically C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\mastlog.ldf).
-c
Shortens startup time when starting SQL Server from the command prompt. Typically, the SQL Server Database Engine starts as a service by calling the Service Control Manager. Because the SQL Server Database Engine does not start as a service when starting from the command prompt, use -c to skip this step.
-f
Starts an instance of SQL Server with minimal configuration. This is useful if the setting of a configuration value (for example, over-committing memory) has prevented the server from starting.
-g memory_to_reserve
Specifies an integer number of megabytes (MB) of memory that SQL Server will leave available for memory allocations within the SQL Server process, but outside the SQL Server memory pool. The memory outside of the memory pool is the area used by SQL Server for loading items such as extended procedure .dll files, the OLE DB providers referenced by distributed queries, and automation objects referenced in Transact-SQL statements. The default is 256 MB.
-h
Reserves virtual address space for Hot Add memory metadata when AWE is enabled with 32-bit SQL Server 2005. Required for Hot-Add memory with 32-bit AWE, but consumes about 500 MB of virtual address space and makes memory tuning more difficult. Not required for 64-bit SQL Server. Hot Add Memory is only available for Windows Server 2003, Enterprise and Datacenter editions.
-m
Starts an instance of SQL Server in single-user mode. When you start an instance of SQL Server in single-user mode, only a single user can connect, and the CHECKPOINT process is not started. CHECKPOINT guarantees that completed transactions are regularly written from the disk cache to the database device.
-n
Does not use the Windows application log to record SQL Server events. If you start an instance of SQL Server with -n, we recommend that you also use the -e startup option. Otherwise, SQL Server events are not logged.
-s
Allows you to start a named instance of SQL Server 2005. Without the -s parameter set, the default instance will try to start. You must switch to the appropriate BINN directory for the instance at a command prompt before starting sqlservr.exe. For example, if Instance1 were to use \mssql$Instance1 for its binaries, the user must be in the \mssql$Instance1\binn directory to start sqlservr.exe -s instance1.
-T trace#
Indicates that an instance of SQL Server should be started with a specified trace flag (trace#) in effect.
-x
Disables the keeping of CPU time and cache-hit ratio statistics. Allows maximum performance.
-d master_file_path
The fully qualified path for the master database file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\master.mdf). If you do not provide this option, the existing registry parameters are used.
-e error_log_path
The fully qualified path for the error log file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG). If you do not provide this option, the existing registry parameters are used.
-l master_log_path
The fully qualified path for the master database log file (typically C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\mastlog.ldf).
-c
Shortens startup time when starting SQL Server from the command prompt. Typically, the SQL Server Database Engine starts as a service by calling the Service Control Manager. Because the SQL Server Database Engine does not start as a service when starting from the command prompt, use -c to skip this step.
-f
Starts an instance of SQL Server with minimal configuration. This is useful if the setting of a configuration value (for example, over-committing memory) has prevented the server from starting.
-g memory_to_reserve
Specifies an integer number of megabytes (MB) of memory that SQL Server will leave available for memory allocations within the SQL Server process, but outside the SQL Server memory pool. The memory outside of the memory pool is the area used by SQL Server for loading items such as extended procedure .dll files, the OLE DB providers referenced by distributed queries, and automation objects referenced in Transact-SQL statements. The default is 256 MB.
-h
Reserves virtual address space for Hot Add memory metadata when AWE is enabled with 32-bit SQL Server 2005. Required for Hot-Add memory with 32-bit AWE, but consumes about 500 MB of virtual address space and makes memory tuning more difficult. Not required for 64-bit SQL Server. Hot Add Memory is only available for Windows Server 2003, Enterprise and Datacenter editions.
-m
Starts an instance of SQL Server in single-user mode. When you start an instance of SQL Server in single-user mode, only a single user can connect, and the CHECKPOINT process is not started. CHECKPOINT guarantees that completed transactions are regularly written from the disk cache to the database device.
-n
Does not use the Windows application log to record SQL Server events. If you start an instance of SQL Server with -n, we recommend that you also use the -e startup option. Otherwise, SQL Server events are not logged.
-s
Allows you to start a named instance of SQL Server 2005. Without the -s parameter set, the default instance will try to start. You must switch to the appropriate BINN directory for the instance at a command prompt before starting sqlservr.exe. For example, if Instance1 were to use \mssql$Instance1 for its binaries, the user must be in the \mssql$Instance1\binn directory to start sqlservr.exe -s instance1.
-T trace#
Indicates that an instance of SQL Server should be started with a specified trace flag (trace#) in effect.
-x
Disables the keeping of CPU time and cache-hit ratio statistics. Allows maximum performance.
Attach/Detach
Detaching a Database
To detach an SQL Server 2000 database, you can use the sp_detach_db system stored procedure. This stored procedure can also run UPDATE STATISTICS on all tables before detaching. The syntax for sp_detach_db system stored procedure is as follows:
sp_detach_db [ @dbname = ] 'dbname'
[ , [ @skipchecks = ] 'skipchecks' ]
In the above, the parameters to the stored procedure are as follows:
* [@dbname =] 'dbname' is the database name. 'dbname'is nvarchar(128), a default value is NULL.
* [@skipchecks =] 'skipchecks' The 'skipchecks' parameter indicates will be can UPDATE STATISTICS run or skipped. The 'skipchecks' is nvarchar(10), a default value is NULL. If 'skipchecks' is true, UPDATE STATISTICS is skipped. If 'skipchecks' is false, UPDATE STATISTICS is run.
The following example detaches the pubs database and run UPDATE STATISTICS on all tables before detaching:
EXEC sp_detach_db 'pubs', 'false'
Attaching a Database
When you attach a database, you must specify at least the name and physical location of the primary data file. If one or more of database files have changed location since the database was detached, you must specify the name and physical location of these files in addition to the primary file.
To attach SQL Server 2000 database, you can use the sp_attach_db system stored procedure. The syntax for sp_attach_db system stored procedure is as follows:
sp_attach_db [ @dbname = ] 'dbname',
[ @filename1 = ] 'filename_n' [ ,...16 ]
In the above command:
* [@dbname =] 'dbname'is the database name. dbname is nvarchar(128), a default value is NULL.
* [@filename1 =] 'filename_n'Is the database file name. filename_n is nvarchar(260), a default value is NULL. There can be up to 16 file names specified.
This is the example to attach the pubs database which contain two files pubs.mdf and pubs_log.ldf from the C:\MSSQL\Data directory:
EXEC sp_attach_db @dbname = 'pubs',
@filename1 = 'C:\MSSQL\Data\pubs.mdf',
@filename2 = 'C:\MSSQL\Data\pubs_log.ldf'
Attaching a Single-File Database
A single-file database is a database that have only one data file. When a database comprises only one data file, the database can be attached to an instance of SQL Server 2000 without using the transaction log file. When the data file will be attached, SQL Server will create a new transaction log file automatically.
To attach a single-file database, you can use the sp_attach_single_file_db system stored procedure. The syntax for sp_attach_single_file_db system stored procedure is as follows:
sp_attach_single_file_db [ @dbname = ] 'dbname'
, [ @physname = ] 'physical_name'
* [@dbname =] 'dbname' is the database name. 'dbname' is nvarchar(128), a default value is NULL.
* [@physname =] 'phsyical_name' is the database file name. 'phsyical_name' is nvarchar(260), a default value is NULL.
This is the example to attach only one data file of the pubs database from the C:\MSSQL\Data directory:
EXEC sp_attach_single_file_db @dbname = 'pubs',
@physname = 'C:\MSSQL\Data\pubs.mdf'
To detach an SQL Server 2000 database, you can use the sp_detach_db system stored procedure. This stored procedure can also run UPDATE STATISTICS on all tables before detaching. The syntax for sp_detach_db system stored procedure is as follows:
sp_detach_db [ @dbname = ] 'dbname'
[ , [ @skipchecks = ] 'skipchecks' ]
In the above, the parameters to the stored procedure are as follows:
* [@dbname =] 'dbname' is the database name. 'dbname'is nvarchar(128), a default value is NULL.
* [@skipchecks =] 'skipchecks' The 'skipchecks' parameter indicates will be can UPDATE STATISTICS run or skipped. The 'skipchecks' is nvarchar(10), a default value is NULL. If 'skipchecks' is true, UPDATE STATISTICS is skipped. If 'skipchecks' is false, UPDATE STATISTICS is run.
The following example detaches the pubs database and run UPDATE STATISTICS on all tables before detaching:
EXEC sp_detach_db 'pubs', 'false'
Attaching a Database
When you attach a database, you must specify at least the name and physical location of the primary data file. If one or more of database files have changed location since the database was detached, you must specify the name and physical location of these files in addition to the primary file.
To attach SQL Server 2000 database, you can use the sp_attach_db system stored procedure. The syntax for sp_attach_db system stored procedure is as follows:
sp_attach_db [ @dbname = ] 'dbname',
[ @filename1 = ] 'filename_n' [ ,...16 ]
In the above command:
* [@dbname =] 'dbname'is the database name. dbname is nvarchar(128), a default value is NULL.
* [@filename1 =] 'filename_n'Is the database file name. filename_n is nvarchar(260), a default value is NULL. There can be up to 16 file names specified.
This is the example to attach the pubs database which contain two files pubs.mdf and pubs_log.ldf from the C:\MSSQL\Data directory:
EXEC sp_attach_db @dbname = 'pubs',
@filename1 = 'C:\MSSQL\Data\pubs.mdf',
@filename2 = 'C:\MSSQL\Data\pubs_log.ldf'
Attaching a Single-File Database
A single-file database is a database that have only one data file. When a database comprises only one data file, the database can be attached to an instance of SQL Server 2000 without using the transaction log file. When the data file will be attached, SQL Server will create a new transaction log file automatically.
To attach a single-file database, you can use the sp_attach_single_file_db system stored procedure. The syntax for sp_attach_single_file_db system stored procedure is as follows:
sp_attach_single_file_db [ @dbname = ] 'dbname'
, [ @physname = ] 'physical_name'
* [@dbname =] 'dbname' is the database name. 'dbname' is nvarchar(128), a default value is NULL.
* [@physname =] 'phsyical_name' is the database file name. 'phsyical_name' is nvarchar(260), a default value is NULL.
This is the example to attach only one data file of the pubs database from the C:\MSSQL\Data directory:
EXEC sp_attach_single_file_db @dbname = 'pubs',
@physname = 'C:\MSSQL\Data\pubs.mdf'
Subscribe to:
Posts (Atom)