Вы находитесь на странице: 1из 12

Creating and Maintaining Databases

Databases

A database consists of a collection of tables that contain data and other objects, such as views, indexes, stored procedures and triggers, defined to support activities performed with the data. When designing the database, consider The purpose of the database and how it affects the design. Create a database plan to fit your purpose Database normalization rules that prevent mistakes in the database design. Protection of your data integrity. Security requirements of the database and user permissions.

Creating database Plan

The first step in creating a database is creating a plan that serves both as a guide to be used when implementing the database and as a functional specification for the database after it has been implemented.

System databases and data

Logical Database Components


Pages and Extents The fundamental unit of data storage in SQL Server 2000 is the page, which is 8KB in size. In SQL Server 2000 databases have 128 pages per megabyte.

Physical Database Files and Filegroups


SQL Server 2000 maps a database over a set of operating-system files. Data and log information are never mixed on the same file, and individual files are used only by one database. SQL Server 2000 databases have three types of files:

Primary Data files Secondary data files Log files

Primary data files


The primary data file is starting point of the database and points to the other files in the database. Every database had one primary data file. The recommended file name extension for primary data files is .mdf.

Secondary data files


Secondary data files comprise all of the data files other than the primary data file. Some databases may not have secondary data files, while others have multiple secondary data files. The recommend file name extension for secondary data files is .ndf.

Log files
Log files hold all of the log information used to recover the database. There must be at least one log file for each database, although there can be more than one. The recommended file name extension for log files is .ldf.

Create Database Command


CREATE DATABASE database_name [ ON [PRIMARY] [ <filespec> [,...n] ] [, <filegroup> [,...n] ] ] [ LOG ON { <filespec> [,...n]} ] [ FOR LOAD | FOR ATTACH ] <filespec> ::= ( [ NAME = logical_file_name, ] FILENAME = 'os_file_name' [, SIZE = size] [, MAXSIZE = { max_size | UNLIMITED } ] [, FILEGROWTH = growth_increment] ) [,...n] <filegroup> ::= FILEGROUP filegroup_name <filespec> [,...n]

DROP DATABASE

Removes one or more databases from Microsoft SQL ServerTM. Removing a database deletes the database and the disk files used by the database. Syntax:DROP DATABASE database_name[,n]

Вам также может понравиться