我正在安装here的AdventureWorks 2008
示例数据库。我在SQLCMD
模式下在SQL Server 2008中执行以下脚本,但收到错误
Msg 102,Level 15,State 1,Line 28
':'附近的语法不正确。
Microsoft SQL Server 2008(RTM) - 10.0.1600.22(X64)2008年7月9日14:17:44
版权所有(c)1988-2008 Microsoft Corporation Developer Windows NT 6.1(Build 7600:)上的版本(64位)开始 - 2013-04-07 10:46:30.423
*删除数据库
*创建数据库Msg 5105,Level 16,State 2,Line 2
发生文件激活错误。物理文件名 '$(SqlSamplesDatabasePath)AdventureWorks2008_Data.mdf'可能是 不正确。诊断并更正其他错误,然后重试 操作。Msg 1802,Level 16,State 1,Line 2
CREATE DATABASE失败。 无法创建列出的某些文件名。检查相关错误。Msg 5011,Level 14,State 5,Line 2
用户无权更改 数据库'AdventureWorks2008',数据库不存在,或者 数据库不处于允许访问检查的状态。Msg 5069,Level 16,State 1,Line 2
ALTER DATABASE语句失败。Msg 911,Level 16,State 1,Line 2
数据库'AdventureWorks2008'不存在。确保正确输入名称。 。
这是我正在使用的脚本的一部分:
/*============================================================================
File: instawdb.sql
Summary: Creates the AdventureWorks 2008R2 OLTP sample database.
SQL Server Version: 10.50.1600
------------------------------------------------------------------------------
This file is part of the Microsoft SQL Server Code Samples.
Copyright (C) Microsoft Corporation. All rights reserved.
This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation. See these other
materials for detailed information regarding Microsoft code samples.
All data in this database is ficticious.
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
============================================================================*/
-- Be sure to enable FULL TEXT SEARCH before running this script
-->> WARNING: THIS SCRIPT MUST BE RUN IN SQLCMD MODE INSIDE SQL SERVER MANAGEMENT STUDIO. <<--
:on error exit
-- IMPORTANT
/*
* In order to run this script manually, either set the environment variables,
* or uncomment the setvar statements and provide the necessary values if
* the defaults are not correct for your installation.
*/
setvar SqlSamplesDatabasePath "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA"
setvar SqlSamplesSourceDataPath "C:\Users\DEVESH\Downloads\"
IF '$(SqlSamplesSourceDataPath)' IS NULL OR '$(SqlSamplesSourceDataPath)' = ''
BEGIN
RAISERROR(N'The variable SqlSamplesSourceDataPath must be defined.', 16, 127) WITH NOWAIT
RETURN
END
IF '$(SqlSamplesDatabasePath)' IS NULL OR '$(SqlSamplesDatabasePath)' = ''
BEGIN
RAISERROR(N'The variable SqlSamplesDatabasePath must be defined.', 16, 127) WITH NOWAIT
RETURN
END
SET NOCOUNT OFF;
GO
PRINT CONVERT(varchar(1000), @@VERSION);
GO
PRINT '';
PRINT 'Started - ' + CONVERT(varchar, GETDATE(), 121);
GO
答案 0 :(得分:1)
问题可能是您没有像脚本警告那样在SQLCMD模式下运行它:
-->> WARNING: THIS SCRIPT MUST BE RUN IN SQLCMD MODE INSIDE SQL SERVER MANAGEMENT STUDIO. <<--
有关如何在SQL Server Management Studio中切换到SQLCMD模式的信息,请参阅http://www.mssqltips.com/sqlservertip/2405/sql-server-management-studio-sqlcmd-mode-option/。