如何创建存储过程来创建数据库

时间:2009-07-10 06:45:57

标签: sql-server sql-server-2008

我需要代码来创建数据库。

1 个答案:

答案 0 :(得分:6)

CREATE DATABASE database_name 
[ ON 
    [ < filespec > [ ,...n ] ] 
    [ , < filegroup > [ ,...n ] ] 
] 
[ LOG ON { < filespec > [ ,...n ] } ] 
[ COLLATE collation_name ]
[ FOR LOAD | FOR ATTACH ] 

< filespec > ::= 

[ PRIMARY ]
( [ NAME = logical_file_name , ] 
    FILENAME = 'os_file_name' 
    [ , SIZE = size ] 
    [ , MAXSIZE = { max_size | UNLIMITED } ] 
    [ , FILEGROWTH = growth_increment ] ) [ ,...n ]

< filegroup > ::= 

FILEGROUP filegroup_name < filespec > [ ,...n ]

一个例子,

USE master
GO
CREATE DATABASE Sales
ON 
( NAME = Sales_dat,
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\saledat.mdf',
   SIZE = 10,
   MAXSIZE = 50,
   FILEGROWTH = 5 )
LOG ON
( NAME = 'Sales_log',
   FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
   SIZE = 5MB,
   MAXSIZE = 25MB,
   FILEGROWTH = 5MB )
GO

参考:MSDN