master中的数据库创建

时间:2013-07-19 06:55:01

标签: sql sql-server ssms

现在这里是我试图运行以执行脚本的查询,该脚本将根据脚本构建我的数据库:

USE master
GO
if exists (select * from sysdatabases where name='Northwind')
        drop database Northwind
go

DECLARE @device_directory NVARCHAR(520)
SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1

EXECUTE (N'CREATE DATABASE Northwind
  ON PRIMARY (NAME = N''Northwind'', FILENAME = N''' + @device_directory + N'northwnd.mdf'')
   LOG ON (NAME = N''Northwind_log'',  FILENAME = N''' + @device_directory + N'northwnd.ldf'')')
go

exec sp_dboption 'Northwind','trunc. log on chkpt.','true'
exec sp_dboption 'Northwind','select into/bulkcopy','true'
GO

现在这里出现错误......

Msg 262, Level 14, State 1, Line 1
CREATE DATABASE permission denied in database 'master'.
Msg 15010, Level 16, State 1, Procedure sp_dboption, Line 64
The database 'Northwind' does not exist. Supply a valid database name. To see available databases, use sys.databases. 

Msg 15010, Level 16, State 1, Procedure sp_dboption, Line 64
The database 'Northwind' does not exist. Supply a valid database name. To see available databases, use sys.databases. 

请帮忙!数据库现在应该在master中制作,但不是!

1 个答案:

答案 0 :(得分:0)

您应该具有CREATE DATABASE权限来创建新的数据库。如果您不熟悉此主题,请尝试以“sa”用户身份登录(如果您知道密码),或要求管理员在SQL Server中将您的登录名添加到“sysadmin”角色。