我想创建一个创建数据库的SQL脚本。现在,我有这样的:使用默认路径中的文件创建数据库
CREATE DATABASE [Documents] ON PRIMARY
(NAME = N'Documents', FILENAME = N'Documents.mdf')
LOG ON
(NAME = N'Documents_log', FILENAME = N'Documents_log.ldf')
COLLATE SQL_Latin1_General_CP1_CI_AS
然而,这会产生以下错误:
Msg 5105, Level 16, State 2, Line 2
A file activation error occurred. The physical file name 'Documents.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
Msg 1802, Level 16, State 1, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
我知道这个问题是我没有为指定文件名完全合格的路径。但是我希望能够运行这个脚本,而不管数据库服务器的目录结构如何。有什么方法可以使用默认路径吗?
是的,但是如果我需要指定像SIZE和FILEGROWTH这样的其他属性呢? 我见过使用XP的解决方案来读取注册表,但如果你没有运行在默认实例上呢?该注册表项/值不会给出正确答案。 仍在搜索,所以我不认为这回答了我自己。 – 2010-07-29 13:25:54
创建数据库后,添加alter database脚本以指定其他属性,如SIZE和FILEGROWTH。 – 2012-10-24 03:15:54