SQL语句操作数据库小结


创建数据库
create database kyuhyun2
on
(
 name='kyuhyun_db.mdf',
 filename='E:\data1\kyuhyun_db.mdf',
 size=3mb,
 maxsize=20mb,
 filegrowth=1mb
),
filegroup kyu
(
 name='kyuhyun_db.ndf',
 filename='E:\data\kyuhyun_db.ndf',
 size=4mb,
 maxsize=15mb,
 filegrowth=1mb
)
log on
(
 name='kyuhyun_log.ldf',
 filename='E:\data\kyuhyun_log.ldf',
 size=3mb,
 maxsize=20mb,
 filegrowth=1mb
)

查询数据库
sp_helpdb kyuhyun mydb

修改数据库名称
alter database kyuhyun modify name=ryeowook

存储过程修改数据库名称 将ryeowook改为kyuhyun
exec sp_dboption 'ryeowook' ,'single',true
exec sp_renamedb 'ryeowook','kyuhyun'
exec sp_dboption 'kyuhyun','single',false

修改文件大小
use master
alter database kyuhyun
modify file
(
 name='kyuhyun_db.mdf',
 size=4mb,
 filegrowth=2mb
)

增加数文件组据库
use master
alter database kyuhyun
add file
(
 name='kyuhyun_db1',
 filename='E:\data\kyuhyun_db1.ndf',
 size=6mb,
 filegrowth=1%
)
drop database kyuhyun  删除数据库

分离数据库
exec sp_detach_db kyuhyun 

附加数据库
exec sp_attach_db kyuhyun, 'E:\data\kyuhyun_db.mdf'

备份数据库
backup database kyuhyun to
disk='C:\data\database_bak.dat' with name='backup'

还原数据库
restore database kyuhyun from disk='E:\data\database_bak.dat' with replace


创建数据库快照
create database mydb0703
on
(
name='kyuhyun_db.mdf',
filename='C:\data\mydb0703.mdf'
)
as snapshot of kyuhyun
restore database kyuhyun2 from database_snapshot='mydb0703'

sp_helpdb mydb0703

恢复数据库快照
restore database kyuhyun from database_snapshot='mydb0703' 

自定义数据类型
exec sp_addtype nameType,‘nvarchar(20)’, ‘NOT NULL’
exec  sp_droptype nameType

 

 

你可能感兴趣的:(数据库,职场,sql语句,休闲)