sqlcmd语法问题

o75abkj4  于 2021-07-29  发布在  Java
关注(0)|答案(0)|浏览(160)

我正在尝试运行一些sqlcmd来在新服务器上创建新的数据库,但是每次运行脚本时,我都会在“s”附近得到不正确的语法,并且不知道确切的原因。命令行是从脚本创建一个新的数据库这是有问题的行:sqlcmd-s sso srvtest-d test-i“c:\test\1\u createdb.sql”这是我用来创建和执行命令行的脚本

SET @Command = 'DIR /B /O:-N ' + @ScriptFilesDir + '*.sql';
INSERT INTO @FileList (FileName) EXEC xp_cmdshell @Command; 
DELETE FROM @FileList WHERE FileName IS NULL OR FileName NOT LIKE '%.sql';
DELETE FROM @FileList WHERE LEFT(FILENAME,1) = '_';

UPDATE @FileList SET Command = 'sqlcmd -S ' + @ServerName 
                         + ' -d ' + @DbName + ' -i "' + @ScriptFilesDir + FileName 
                         + '" >> ' + @ScriptFilesDir + 'Output.txt';

--select * from @FileList
-- Run the script files one by one on each of the specified databases 
PRINT 'Running Scripts...'

SELECT @FileNumber = MAX(FileNumber) FROM @FileList; 
WHILE (@FileNumber > 0)
BEGIN
    SELECT @FileNumber = @FileNumber - 1, @FileName = FileName, @Command = Command 
    FROM @FileList 
    WHERE FileNumber = @FileNumber; 

    RAISERROR ('    Executing file %s',0, 1, @FileName) WITH NOWAIT

    SET @Command1 = 'ECHO ' + @FileName + ': >> ' + @ScriptFilesDir + 'Output.txt';
    EXEC xp_cmdshell @Command1, NO_OUTPUT;

    SET @Command1 = REPLACE(@Command, '%DATABASE%', @DBName);
    PRINT @Command1
    EXEC xp_cmdshell @Command1, NO_OUTPUT;
END
PRINT 'Running Scripts Complete'

基本上,这个脚本通过一些脚本来创建数据库、视图、sp、函数、索引等。。这个脚本是从ssms执行的为什么我会得到这个错误?
谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题