我想创建一个创建数据库的SQL脚本。现在,我有这个: ' ~ |8 D: o$ B7 r1 a7 r% }CREATE DATABASE [Documents] ON PRIMARY / l w7 b" U: y+ m
( NAME = N'Documents', FILENAME = N'Documents.mdf')/ Z$ B. R M8 v$ o k7 o
LOG ON 7 w0 H9 b0 \: V1 a
( NAME = N'Documents_log', FILENAME = N'Documents_log.ldf')5 J; \( S! ?! g. u& _$ i
COLLATE SQL_Latin1_General_CP1_CI_AS / }; v; q( b k N3 c8 Y但是,这会产生以下错误:/ e4 v3 D9 k8 S6 _2 ?$ P
Msg 5105, Level 16, State 2, Line 2 ( G9 z( M- Y2 }& G9 M& EA file activation error occurred. The physical file name 'Documents.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.& \' i8 j/ A* v8 h' Z9 d
Msg 1802, Level 16, State 1, Line 2 ' p7 Z v" V! O1 x/ O+ BCREATE DATABASE failed. Some file names listed could not be created. Check related errors." Y K! x) |2 n; G$ {% Y H6 ]
我知道问题是我没有为文件名指定完全限定的路径。但是我希望能够运行此脚本,而不管数据库服务器的目录结构如何。有什么方法可以使用默认路径?$ X2 ?& y! d9 C; N1 z
' E' M7 n& x+ a: P6 _6 K 解决方案:9 t2 \7 T" f/ K6 D9 c" A
& Z8 L+ Q% j5 q8 k0 ]4 H1 ^/ i% \6 O# V
0 n) o9 a) w7 F$ O0 f3 a4 T
您可以在不指定文件详细信息的情况下创建数据库,例如: 6 s7 s! J( k1 u; w& A w5 P& ^CREATE DATABASE Documents;