Sqlcmd: Error: Syntax error at line 17 near command ':r ' in file

梦想的初衷 提交于 2020-03-05 21:21:11

问题


I need to execute multiple sql files using a batch file. So, I created a file CREATE_DB.sql with following code:

/* SCRIPT: CREATE_DB.sql */
/* BUILD A DATABASE */

-- This is the main caller for each script
SET NOCOUNT ON
GO

PRINT 'CREATING DATABASE'
IF EXISTS (SELECT 1 FROM SYS.DATABASES WHERE NAME = 'MSSQLTIPS')
DROP DATABASE MSSQLTIPS
GO
CREATE DATABASE MSSQLTIPS
GO

:On Error exit

:r  C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\CREATE_TABLES.sql
:r  C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\TABLE_INSERTS.sql
:r  C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\CREATE_INDEXES.sql
:r  C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\CREATE_PROCEDURES.sql

PRINT 'DATABASE CREATE IS COMPLETE'
GO

Then, I create a batch file create_db.bat with following code:

    SQLCMD -E -dmaster -i"C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\create_db.sql"
PAUSE

But, on double-clicking the batch file it shows the following error:

Sqlcmd: Error: Syntax error at line 17 near command ':r         ' in file 'C:\Users\XYZ\Documents\SQL Server Management Studio\BATCheck\create_db.sql'.

This, I think, is due to the Spaces in the file paths, but how to get rid of this error?

来源:https://stackoverflow.com/questions/29182452/sqlcmd-error-syntax-error-at-line-17-near-command-r-in-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!