New! – Try automated migration testing Learn more

Flyway Documentation

Poll

DB2

Supported Variants

  • LUW

Supported Versions

Support Level

Compatible
Certified
Guaranteed Flyway Teams

Support Level determines the degree of support available for this database (learn more).

Driver

URL format jdbc:db2://host:port/database
Ships with Flyway Command-line No
Maven Central coordinates com.ibm.db2.jcc:11.5.0.0
Supported versions 4.16.53 and later. For versions prior to 11.5, follow instructions on ibm.com
Default Java class com.ibm.db2.jcc.DB2Driver

SQL Script Syntax

Compatibility

  • DDL exported by DB2 can be used unchanged in a Flyway migration
  • Any DB2 SQL script executed by Flyway, can be executed by db2 (after the placeholders have been replaced).

Example

/* Single line comment */
CREATE TABLE test_user (
 name VARCHAR(25) NOT NULL,
 PRIMARY KEY(name)
);

/*
Multi-line
comment
*/

-- Placeholder
INSERT INTO ${tableName} (name) VALUES ('Mr. T');

-- SQL-PL
CREATE TRIGGER uniqueidx_trigger BEFORE INSERT ON usertable
	REFERENCING NEW ROW AS newrow
    FOR EACH ROW WHEN (newrow.name is not null)
	BEGIN ATOMIC
      IF EXISTS (SELECT * FROM usertable WHERE usertable.name = newrow.name) THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'duplicate name';
      END IF;
    END;

-- Terminator changes
--#SET TERMINATOR @
CREATE FUNCTION TEST_FUNC(PARAM1 INTEGER, PARAM2 INTEGER)
  RETURNS INTEGER
LANGUAGE SQL
  RETURN
  1@   
--#SET TERMINATOR ;
CREATE FUNCTION TEST_FUNC(PARAM1 INTEGER, PARAM2 INTEGER, PARAM3 INTEGER)
  RETURNS INTEGER
LANGUAGE SQL
  RETURN
  1;

Limitations

  • None

MySQL