我有一个SQL Server Dockerfile,其中的import-data.sh从sql-data文件夹导入*.sql
文件。如果我从Datagrip之类的工具运行*.sql
文件,一切都会正常,但是自动运行时导入失败并显示此错误消息。
错误消息:
1934年,消息16级,状态1,第4行
CREATE INDEX失败,因为以下SET选项的设置不正确:“ QUOTED_IDENTIFIER”。验证SET选项是否正确用于计算列的索引视图和/或索引和/或过滤后的索引和/或查询通知和/或XML数据类型方法和/或空间索引操作。
Dockerfile
FROM microsoft/mssql-server-linux:2017-latest
RUN mkdir /sql-data/
EXPOSE 1433
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY import-data.sh /usr/src/app/
RUN chmod +x /usr/src/app/import-data.sh
# Copy SQL Scripts to sql-data for processing
COPY ./sql-data/*.sql /sql-data/
CMD /bin/bash /usr/local/bin/entrypoint.sh
entrypoint.sh
#!/bin/bash
#start SQL Server, start the script to create the DB and import the data, start the app
/usr/src/app/import-data.sh & /opt/mssql/bin/sqlservr
import-data.sh
#!/bin/bash
# wait for the SQL Server to come up https://github.com/twright-msft/mssql-node-docker-demo-app/issues/11
while [ ! -f /var/opt/mssql/log/errorlog ]
do
sleep 2
done
## tail the error log for the startup dll and then quit
tail -f /var/opt/mssql/log/errorlog | while read LOGLINE
do
[[ "${LOGLINE}" == *"Using 'xpstar.dll' version"* ]] && pkill -P $$ tail
done
echo "Running SQL Scripts"
# Scan for SQL files and load them in
for file in /sql-data/*.sql; do
echo $file
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i $file
done
/sql-data/setup.sql
IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = 'Products')
BEGIN
CREATE DATABASE Products;
END
GO
USE Products;
GO
答案 0 :(得分:4)
不幸的是,出于向后兼容的原因,SQLCMD实用程序默认为=INDEX(Sheet2!$B$2:$B$9,MOD(A2,ROWS(Sheet2!$B$2:$B$9)+1))
。 Specify the -I
argument so that QUOTED_IDENTIFIER ON
is used.
QUOTED_IDENTIFIER OFF
答案 1 :(得分:1)
SQL Server Management Studio和Datagrip之类的工具默认情况下已打开“引用标识符”。您必须通过将SQL脚本修改为SET QUOTED_IDENTIFIER ON
您将像这样修改setup.sql脚本:
/sql-data/setup.sql
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = 'Products')
BEGIN
CREATE DATABASE Products;
END
GO
USE Products;
GO