Bootstrap

创建和管理数据库(SQL server)

一.数据库的创建

create database XXX
on primary
(
	name=xxx_data,
	filename='D:\DATA\xxx.mdf',
	size=100MB,
	maxsize=UNLIMITED,
	filegrowth=20%
)
log on
(
	name=xxx_log,
	filename='D:\DATA\xxx.ldf',
	size=10MB,
	maxsize=50MB,
	filegrowth=1MB

二.数据库的管理

1.增加日志文件
alter database XXX
add log file
(
	name=xxx01_log,
	filename='D:\DATA\xxx01_log.ldf',
	size=50MB
)
2.增加文件组
alter database XXX
add filegroup data
go
alter database XXX
add file
(
	name=xxx02_data,
	filename='D:\DATA\xxx02_data.ndf'
),
(
	name=xscj3_data,
	filename='D:\DATA\xxx03_data.ndf'
) to filegroup data
3.修改主数据文件
alter database XXX
modify file
(
	name=xxx_data,
	size=20MB
)
4.分离数据库
exec sp_detach_db XXX
5.附加数据库
exec sp_attach_db @dbname='XXX',@filename1='D:\DATA\xxx.mdf',
@filename2='D:\DATA\xxx.ldf'
6.删除数据库
drop database XXX

;