Microsoft SQL Server to IBM DB2 Migration

SQLines tools can help you transfer data, convert database schema (DDL), views, stored procedures, functions, triggers, queries and SQL scripts from Microsoft SQL Server (MSSQL, MS SQL), Azure SQL Database, Azure Synapse to IBM DB2:

  • SQLines Data - Data transfer, schema migration and validation tool
  • SQLines SQL Converter - SQL scripts conversion tool. Try Online

Databases:

  • Microsoft SQL Server 2022, 2019, 2017, 2016, 2014, 2012, 2008, 2005 and 2000
  • IBM DB2 for LUW, z/OS and OS/400 11.x, 10.x, 9.x, 8.x and 7.x

Migration Reference

Data Types

Converting data types:

SQL Server DB2
CHAR Fixed-length character string CHAR
INT, INTEGER 32-bit integer INT, INTEGER
SMALLINT 16-bit integer SMALLINT
VARCHAR Variable-length character string VARCHAR

CREATE TABLE Statement

Converting table definitions:

SQL Server DB2
1 IDENTITY(start, increment) Identity column GENERATED ALWAYS AS IDENTITY
(START WITH start INCREMENT BY increment)
2 PRIMARY KEY (col ASC, … ) Primary key PRIMARY KEY (col, … ) ASC, DESC cannot be specified

SELECT Statement

Converting SQL queries:

SQL Server DB2
1 SELECT … FROM Result set from a procedure DECLARE CURSOR WITH RETURN and OPEN

INSERT Statement

Converting SQL INSERT statement:

SQL Server DB2
1 INSERT [INTO] table INSERT INTO table INTO keyword is required

CREATE FUNCTION Statement

Converting Transact-SQL user-defined functions:

SQL Server DB2
1 CREATE FUNCTION | ALTER FUNCTION name CREATE OR REPLACE FUNCTION name
2 @param [AS] datatype = default p_param datatype DEFAULT default
3 RETURNS datatype(len) RETURNS datatype(len)
4 Optional AS before the function body Removed
5 Optional statement delimiter ; is added after each statement

For more information, see Conversion of Transact-SQL Statements.

CREATE PROCEDURE Statement

Converting Transact-SQL stored procedures:

SQL Server DB2
1 CREATE PROCEDURE name CREATE OR REPLACE PROCEDURE name
2 @param [AS] datatype = default p_param datatype DEFAULT default
3 Optional AS before the procedure body Removed
4 Optional statement delimiter ; is added after each statement
5 GO command at the end of procedure Removed

For more information, see Conversion of Transact-SQL Statements.

Transact-SQL Statements

Variable declaration and assignment:

SQL Server DB2
1 DECLARE @v1 type1, @v2 type2, … DECLARE v1 type1; DECLARE v2 type2, DECLARE …

SQL Statements

Converting SQL statements:

SQL Server DB2
1 USE name Change the database SET SCHEMA 'name' If databases are mapped to schemas