updateSQL
command
The updateSQL
command is a helper command that allows you to inspect the SQL Liquibase will run while using the update command.
Uses
The updateSQL
command is used when you want to inspect the raw SQL before running the update command, so you can correct any issues that may arise before running the command. Liquibase uses the raw SQL to apply database changes you have added to the changelog file.
Running the updateSQL
command
To run the updateSQL
command, you need to specify your driver, class path, URL, and user authentication information in your liquibase.properties
file. For more information, see Creating and configuring a liquibase.properties file. You can also specify these properties in your command line.
Then run the updateSQL
command:
liquibase --changeLogFile=sample.changelog.xml updateSQL
Note: Enter the name of the changelog you want to use in place of sample.changelog.xml
.
updateSQL
global attributes
Attribute | Definition | Requirement |
---|---|---|
--changeLogFile * |
Specifies the root changelog | Required |
--url
|
Specifies the JDBC database connection URL | Required |
--username
|
Specifies the database username | Required |
--password
|
Specifies the database password | Required |
--outputFile ** |
Specifies the file path to where the update SQL will be written | Optional |
* Liquibase checks the changelog and any nested changelogs for the definitions of the changesets to update.
* * If not specified, update
SQL output goes to STDOUT
.
updateSQL
command attributes
Attribute | Definition | Requirement |
---|---|---|
--labels
|
Tags you can add to changesets to determine which changesets in the changelog to evaluate based on their labels | Optional |
--contexts
|
Expressions you can add to changesets to determine which changesets in the changelog to evaluate based on their contexts | Optional |

Liquibase Community 3.8.9 by Datical
-- *********************************************************************
-- Update Database Script
-- *********************************************************************
-- Change Log: sample.changelog.xml
-- Ran at: 19.05.20, 14:04
-- Against: DBUSER@jdbc:h2:tcp://localhost:9090/mem:dev
-- Liquibase version: 3.8.9
-- *********************************************************************
-- Lock Database
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = TRUE, LOCKEDBY = 'if34 (10.255.242.112)', LOCKGRANTED = '2020-05-19 14:04:38.862' WHERE ID = 1 AND LOCKED = FALSE;
-- Changeset sample.changelog.xml::4::your.name
ALTER TABLE PUBLIC.person ADD worksfor_company_id INT;
INSERT INTO PUBLIC.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('4', 'your.name', 'sample.changelog.xml', NOW(), 4, '8:f66cab80c4377763692504b82e0fd960', 'addColumn tableName=person', '', 'EXECUTED', NULL, NULL, '3.8.9', '9886280912');
-- Changeset sample.changelog.xml::5::your.name
ALTER TABLE PUBLIC.person ADD CONSTRAINT fk_person_worksfor FOREIGN KEY (worksfor_company_id) REFERENCES PUBLIC.company (id);
INSERT INTO PUBLIC.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('5', 'your.name', 'sample.changelog.xml', NOW(), 5, '8:db6d8eb91affe0e7ce606de385e87f33', 'addForeignKeyConstraint baseTableName=person, constraintName=fk_person_worksfor, referencedTableName=company', '', 'EXECUTED', NULL, NULL, '3.8.9', '9886280912');
-- Release Database Lock
UPDATE PUBLIC.DATABASECHANGELOGLOCK SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;