提问
本帖最后由 lvjiezi 于 2013-03-22 12:39:57 编辑 做练习的时候按照案例输入了公式
declare @data_path nvarchar(256);
set @data_path=(select SUBSTRING(physical_name, 1, charindex(N'master.mdf',LOWER(physical_name))-1)
FROM master.sys.master_files
WHERE DATABASE_PRINCIPAL_ID= 1 AND FILE_ID = 1);
execute('create database demo on primary
(name = arch1,filename = '''+@data_path + 'demodb1.mdf'',size = 100MB, maxsize = 200,
filegrowth = 20),
(name = arch2,filename = '''+@data_path + 'demodb2.ndf'',size = 100mb, maxsize = 200,
filegrowth = 20),
(name = arch3,filename = '''+@data_path + 'demodb3.ndf'',size = 100mb, maxsize = 200,
filegrowth = 20)
log on
(name = archlog1, filename = '''+@data_path + 'archlog1.ldf'',size = 100 mb, maxsize = 200,
filegrowth = 20),
(name = archlog2, filename = '''+@data_path + 'archlog2.ldf'',size = 100 mb, maxsize = 200,
filegrowth = 20)');
检验过程命令可以通过,但是执行的时候提示(列名 'DATABASE_PRINCIPAL_ID' 无效。),想知道出错在那里,还需要哪些前提条件??
[解决办法]
DECLARE @data_path NVARCHAR(256) ;
SET @data_path = ( SELECT TOP 1
SUBSTRING(physical_name, 1,
CHARINDEX(N'master.mdf',
LOWER(physical_name)) - 1)
FROM master.sys.master_files
WHERE DATABASE_PRINCIPAL_ID() = 1
AND FILE_ID = 1
) ;
EXECUTE('create database demo on primary
(name = arch1,filename = '''+@data_path + 'demodb1.mdf'',size = 100MB, maxsize = 200,
filegrowth = 20),
(name = arch2,filename = '''+@data_path + 'demodb2.ndf'',size = 100mb, maxsize = 200,
filegrowth = 20),
(name = arch3,filename = '''+@data_path + 'demodb3.ndf'',size = 100mb, maxsize = 200,
filegrowth = 20)
log on
(name = archlog1, filename = '''+@data_path + 'archlog1.ldf'',size = 100 mb, maxsize = 200,
filegrowth = 20),
(name = archlog2, filename = '''+@data_path + 'archlog2.ldf'',size = 100 mb, maxsize = 200,
filegrowth = 20)') ;