我正在尝试创建一个数据库,其名称和数据路径取自变量,例如:
declare @DataPath nvarchar(200) = cast(serverproperty('InstanceDefaultDataPath') as nvarchar(200));
declare @Database nvarchar(50) = 'MyDatabaseName';
use master
go
if exists (select name from sys.databases where name = '@Database')
drop database [@Database]
go
create database [@Database]
on primary (
name = '@Database',
filename = concat(@Datapath, '@Database_Data.mdf'),
size = 200MB,
maxsize = 20GB,
filegrowth = 40MB
)
collate Latin1_General_CI_AI
go
我收到错误“代码行上的'语法不正确'('。”:
filename = concat(@Datapath, '@Database_Data.mdf'),
为什么?
答案 0 :(得分:0)
也许你应该使用
name = @Database,
filename = concat(@Datapath, @Database,'_Data.mdf'),
代替?