Unable to run SQL script using liquibase

65 Views Asked by At

This is my SQL script (SQL Server) run-1.sql:

USE \[MyDB\]
GO
BEGIN
SET NOCOUNT ON;
DECLARE @prmName VARCHAR(50)='Laxmi';
INSERT INTO tabletest1(name)
SELECT @prmName
END
GO

change.xml:

<changeSet id="cnfxecute.dev.20240305-3" author="laxmi">
    <sqlFile path="db/scripts/dev/2024/01/run-1.sql"
             splitStatements="false"
             stripComments="GO"/>
</changeSet>

When I run the Azure Pipeline, I get the error below:

BEGIN
SET NOCOUNT ON;
DECLARE @prmName VARCHAR(50)='Laxmi';
INSERT INTO tabletest1(name)
SELECT @prmName
END
GO]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:309)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:113)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1277)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1259)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:582)
    ... 10 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'GO'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:258)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1535)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:845)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:752)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:219)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:199)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:729)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:307)
    ... 15 more

enter image description here

I tried many methods but to no avail. Such as:

<changeSet id="cnfxecute.dev.20240305-3" author="laxmi">
    <sqlFile path="db/scripts/dev/2024/01/run-1.sql"
             splitStatements="false"
             stripComments=";"/>
</changeSet>

I used the following changeset, still I got the error:

<changeSet id="cnfxecute.dev.20240305-3" author="laxmi">
    <sqlFile path="db/scripts/dev/2024/01/run-1.sql"
             splitStatements="false"
             endDelimiter=";"/>
</changeSet>
0

There are 0 best solutions below