sqlFile
The <sqlFile>
Change Type allows you to specify SQL statements in an external file.
Uses
The <sqlFile>
Change Type is useful for complex changes that are not supported through Liquibase automated Change Types such as stored procedures. The SQL contained in the <sqlFile>
Change Type can be multi-line.
Tip: If you use psql, SQL Plus, or sqlcmd utility and Liquibase Pro, see Using the PSQL integration and runWith attribute with Liquibase Pro and PostgreSQL, Using the SQL Plus integration and runWith attribute with Liquibase Pro and Oracle, and Using the SQLCMD integration and runWith attribute with Liquibase Pro and MSSQL Server.
Using the sqlFile
Change Type
<sqlFile>
finds the file by searching in the following order:
- The file is searched for in the classpath. This can be manually set and by default the Liquibase startup script adds the current directory when run.
- The file is searched for using the file attribute as a file name. This allows absolute paths to be used or relative paths to the working directory to be used.
<sqlFile>
supports multiple SQL statements in the same file:
- Single-line SQL statements can be separated using a
;
at the end of the last line of the SQL or aGO
statement. AGO
statement must be on a separate line between the two SQL statements. - Multi-line SQL statements are also supported. Only a
;
orGO
statement will finish a multi-line SQL statement, a new line is not enough. - Files containing a single SQL statement do not need to use a
;
orGO
statement.
<sqlFile>
supports comments using the following formats:
- A multi-line comment that starts with
/*
and ends with*/
. - A single-line comment starting with
--
and finishing at the end of the line.
You can also nest <sqlFile>
within the rollback tag in a changeset:
Note: By default Liquibase will attempt to split statements on a ;
or GO
at the end of lines. If you have a comment or non-statement ending with ;
or GO
, do not include it at the end of a line or you will get invalid SQL.

Currently, there is no SQL Example for the <sqlFile>
Change Type because you can just put SQL directly into a SQL formatted changelog.

<changeSet author="liquibase-docs" id="sqlFile-example">
<sqlFile dbms="!h2, oracle, mysql"
encoding="UTF-8"
endDelimiter="\nGO"
path="my/path/file.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

- changeSet:
id: sqlFile-example
author: liquibase-docs
changes:
- sqlFile:
dbms: '!h2, oracle, mysql'
endDelimiter: \nGO
splitStatements: true
path: my/path/file.sql
stripComments: true

{
"changeSet":{
"id":"sqlFile-example",
"author":"liquibase-docs",
"changes":[
{
"sqlFile":{
"dbms":"!h2, oracle, mysql",
"endDelimiter":"\nGO",
"splitStatements":true,
"path":"my/path/file.sql",
"stripComments":true
}
}
]
}
}
Available attributes
Name | Description | Required for | Supports | Since |
---|---|---|---|---|
dbms
|
Specifies which database types the change must be applied to. Valid database type names are listed on the supported databases page. Separate multiple databases with commas. Specify that a change does not apply to a database type by prefixing it with ! . The keywords all and none are also available. |
all | 3.0 | |
encoding
|
Specifies encoding used in the file defined in the path attribute. |
all | ||
endDelimiter
|
Specifies what character ends a SQL statement. Can be used to override the default value of ; . For example, a stored function that contains the default ; end delimiter to separate the statements inside the function. For more information, see endDelimiter SQL attribute. |
all | ||
path
|
Specifies the file path of the SQL file to load. | all | all | |
relativeToChangelogFile
|
Indicates whether the file path is relative to the root changelog file rather than to the classpath. | all | ||
splitStatements
|
Set to false to not have Liquibase split statements on ;'s and GO's . Defaults to true if not set. |
all | ||
stripComments
|
Set to true to remove any comments in the SQL before executing, otherwise false . |
all |
Database support
Database | Note | Auto rollback |
---|---|---|
DB2/LUW | Supported | No |
DB2/z | Supported | No |
Derby | Supported | No |
Firebird | Supported | No |
H2 | Supported | No |
HyperSQL | Supported | No |
INGRES | Supported | No |
Informix | Supported | No |
MariaDB | Supported | No |
MySQL | Supported | No |
Oracle | Supported | No |
PostgreSQL | Supported | No |
Snowflake | Supported | No |
SQL Server | Supported | No |
SQLite | Supported | No |
Sybase | Supported | No |
Sybase Anywhere | Supported | No |
Snowflake | Supported | No |