SQL SERVER 2012 第五章 创建和修改数据表 の CREATE语句

时间:2021-11-12 07:17:38

CREATE <object type> <object name>

CREATE DATABASE <database name>

比较完整的语法列表: 日志文件和数据库文件不要放在一块磁盘上,争抢磁盘IO,还有危害安全性。

CREATE DATABASE <database name>
[ON [PRIMARY]
  ([NAME = <'logical file name'>,]
  FILENAME = <'file name'>
  [,SIZE = <size in kilobytes,megabytes,gigabytes,or terabytes>]
  [,MAXSIZE = <size in kilobytes,megabytes,gigabytes,or terabytes>]
  [,FILEGROWTH = <kilobytes,megabytes,gigabytes,or terabytes|percentage>])]
[LOG ON
  ([NAME = <'logical file name'>,]
  FILENAME = <'file name'>
  [,SIZE = <size in kilobytes,megabytes,gigabytes,or terabytes>]
  [,MAXSIZE = <size in kilobytes,megabytes,gigabytes,or terabytes>]
  [,FILEGROWTH = <kilobytes,megabytes,gigabytes,or terabytes|percentage>])]
  [CONTAINMENT = OFF|PARTIAL]
  [COLLATE <collation name>]
  [FOR ATTACH [WITH <service broker>] | FOR ATTCH_REBUILD_LOG | WITH DB_CHAINING ON| OFF| TRUSTWORTHY ON|OFF] ----需要实践
  [AS SNAPSHOT OF <source database name>]
[;]

实战:

CREATE DATABASE Accounting
ON
(
NAME = 'Accounting',
FILENAME = 'D:\AccountingData.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5
)
LOG ON
(
NAME = 'AccountingLog',
FILENAME = 'D:\AccountingLog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB
)

sp_help

sp_helpdb

sp_helpdb 'dbname'