很奇怪的问题,大侠帮我看一下
写的T-SQL语句,没有检查出什么错误,不过运行就是会出错。
declare @DBName nvarchar(132)
declare @DBFilePath nvarchar(132),@DBFileName nvarchar(132),@DBLogName nvarchar(132)
declare @DBSize nvarchar(132),@DBMaxsize nvarchar(132),@DBFileGrowth nvarchar(132)
select @DBName= 'xx ', @DBFilePath= 'e:\ '
select @DBFileName=@DBName + '_Dat.mdf ',
@DBLogName=@DBName + '_Log.ldf '
select @DBSize= '5MB ',@DBMaxsize= 'UNLIMITED ',@DBFileGrowth= '10% '
exec
( '
CREATE DATABASE ' ' '+@DBName+ ' ' '
ON
(
NAME= '+@DBFileName+ ',
FILENAME= ' ' '+@DBFilePath + @DBFileName+ ' ' ',
SIZE= '+@DBSize+ '
MAXSIZE= '+@DBMaxsize+ ',
FILEGROWTH = '+@DBFileGrowth+ '
)
LOG ON
(
NAME= '+@DBLogName+ ',
FILENAME= ' ' '+@DBFilePath + @DBLogName+ ' ' ',
SIZE= '+@DBSize+ '
MAXSIZE= '+@DBMaxsize+ ',
FILEGROWTH= '+@DBFileGrowth+ '
) '
)
运行结果:
服务器: 消息 170,级别 15,状态 1,行 2
第 2 行: 'xx ' 附近有语法错误。
------解决方案--------------------参考正确的写法
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