The concept and operation of the database (database Principle 6)

The concept and operation of the database

table of Contents

First, the basic concept of the database
operation two, the database

First, the basic idea of ​​the database

1, physical database
(1), the type of database file:

  1. Master data file: the starting point of the database, point to other files in the database, each database has one and only one primary data file extension is .mdf
  2. Auxiliary data files: data files other than the main and auxiliary data files are data files, the database may or may not have a secondary data file extension is .ndf
  3. The transaction log file: contains all the log information used to recover the database, each database must have at least one log file extension is .ldf

(2), the database file group: In order to facilitate the management and distribution of data files grouped together. Composition file divided into a main group of user-defined file

  1. Primary file group: contains the primary data file and the specified file is not assigned to another group of data files. The system tables are included in the main file group
  2. User-defined file group: in building a database or modify the database file group statements using keywords specified file group

(3) Application of the rule set file as follows:

  1. A document file can only belong to a group, the same group a file can only belong to a database
  2. Primary file group contains all of the data file system tables and other unspecified group of files
  3. The transaction log files do not belong to any group of files

2, logical database
(1), the system database:

  • master database: Record information about all system-level. Store and manage information in other databases
  • model database: provides a template for user-created database
  • msdb database: agent schedule used when operating the alarm operation and records. When many users simultaneously modify the same data inconsistencies can occur
  • tempdb database: storing temporary tables and temporary objects

(2), user-defined database

Second, the operation of the database

1, to create the database: visual way to create and T-SQL script to create a way to
(1) create a database using the Enterprise Manager visual , learning phase is not generally recommended
(2), create a database using T-SQL script
syntax to create the database:

create database stuDB 
on  primary  -- 默认就属于primary文件组,可省略
(
/*--数据文件的具体描述--*/
    name='stuDB_data',  -- 主数据文件的逻辑名称
    filename='D:\stuDB_data.mdf', -- 主数据文件的物理名称
    size=5mb, --主数据文件的初始大小
    maxsize=100mb, -- 主数据文件增长的最大值
    filegrowth=15%--主数据文件的增长率
)
log on
(
/*--日志文件的具体描述,各参数含义同上--*/
    name='stuDB_log',
    filename='D:\stuDB_log.ldf',
    size=2mb,
    filegrowth=1mb
)

2, modify the database to modify the library has been built
(1), increasing the database space
to increase the size of the existing database file:

alter database 数据库名
modify file
(
	name=''逻辑文件名,
	size=文件大小,
	maxsize=增长限制
)

Increase the database file:

alter database 数据库名
add fille|add log file
(
	name='逻辑文件名',
	filename='物理文件名',
	size='文件大小',
	filegrowth=‘增长限制’
)

(2), has reduced the size of the database file
Here Insert Picture Description
(3), delete the database files

alter database 数据库名
remove file 逻辑文件名

(4), rename the database: ensure that no one is using the database before renaming
using system stored procedures sp_renamedb rename

sp_renamedb [@dbname=] 'old_name',[@newname=]'new_name'
示例:sp_renamedb 'student2','student_back'

3, delete the database
(1), using the delete SSMS
(2), using T-SQL drop database to delete the

drop database 数据库名

Guess you like

Origin blog.csdn.net/y20_20/article/details/92424868