
Mapping Data Types from SQL Server to IBM DB2
The following table shows the data type mappings that are used when data is replicated to a Subscriber running IBM DB2.
|
SQL Server data type
|
IBM DB2 data type
|
|---|
|
bigint
|
DECIMAL(19,0)
|
|
binary(1-254)
|
CHAR(1-254) FOR BIT DATA
|
|
binary(255-8000)
|
VARCHAR(255-8000) FOR BIT DATA
|
|
bit
|
SMALLINT
|
|
char(1-254)
|
CHAR(1-254)
|
|
char(255-8000)
|
VARCHAR(255-8000)
|
|
date
|
DATE
|
|
datetime
|
TIMESTAMP
|
|
datetime2(0-7)
|
VARCHAR(27)
|
|
datetimeoffset(0-7)
|
VARCHAR(34)
|
|
decimal(1-31, 0-31)
|
DECIMAL(1-31, 0-31)
|
|
decimal(32-38, 0-38)
|
VARCHAR(41)
|
|
float(53)
|
DOUBLE
|
|
float
|
FLOAT
|
|
image
|
VARCHAR(0) FOR BIT DATA1
|
|
into
|
INT
|
|
money
|
DECIMAL(19,4)
|
|
nchar(1-4000)
|
VARCHAR(1-4000)
|
|
ntext
|
VARCHAR(0)1
|
|
numeric(1-31, 0-31)
|
DECIMAL(1-31,0-31)
|
|
numeric(32-38, 0-38)
|
VARCHAR(41)
|
|
nvarchar(1-4000)
|
VARCHAR(1-4000)
|
|
nvarchar(max)
|
VARCHAR(0)1
|
|
real
|
REAL
|
|
smalldatetime
|
TIMESTAMP
|
|
smallint
|
SMALLINT
|
|
smallmoney
|
DECIMAL(10,4)
|
|
sql_variant
|
N/A
|
|
sysname
|
VARCHAR(128)
|
|
text
|
VARCHAR(0)1
|
|
time(0-7)
|
VARCHAR(16)
|
|
timestamp
|
CHAR(8) FOR BIT DATA
|
|
tinyint
|
SMALLINT
|
|
uniqueidentifier
|
CHAR(38)
|
|
varbinary(1-8000)
|
VARCHAR(1-8000) FOR BIT DATA
|
|
varchar(1-8000)
|
VARCHAR(1-8000)
|
|
varbinary(max)
|
VARCHAR(0) FOR BIT DATA1
|
|
varchar(max)
|
VARCHAR(0)1
|
|
xml
|
VARCHAR(0)1
|
1 See the next section for more information about mappings to VARCHAR(0).
Data Type Mapping Considerations
Consider the following data type mapping issues when replicating to DB2 Subscribers:
-
When mapping SQL Server char, varchar, binary and varbinary to DB2 CHAR, VARCHAR, CHAR FOR BIT DATA, and VARCHAR FOR BIT DATA, respectively, replication sets the length of the DB2 data type to be the same as that of the SQL Server type.
This allows the generated table to be successfully created at the Subscriber, as long as the DB2 page size constraint is large enough to accommodate the maximum size of the row. Ensure that the login used to access the DB2 database has permissions to access table spaces of a sufficient size for the tables being replicated to DB2.
-
DB2 can support VARCHAR columns as large as 32 kilobytes (KB); therefore it is possible that some SQL Server large object columns can be appropriately mapped to DB2 VARCHAR columns. However, the OLE DB provider that replication uses for DB2 does not support mapping SQL Server large objects to DB2 large objects. For this reason, SQL Server text, varchar(max), ntext, and nvarchar(max) columns are mapped to VARCHAR(0) in the generated create scripts. The length value of 0 must be changed to an appropriate value prior to applying the script to the Subscriber. If the data type length is not changed, DB2 will raise error 604 when the table create is attempted at the DB2 Subscriber (error 604 indicates that the precision or length attribute of a data type is not valid).
Based upon your knowledge of the source table that you are replicating, determine whether it is appropriate to map a SQL Server large object to a variable length DB2 item, and specify an appropriate maximum length in a custom creation script. For information about specifying a custom creation script, see step 5 in the section "Configuring an IBM DB2 Subscriber" in this topic.
Note: |
|---|
|
The specified length for the DB2 type, when combined with other column lengths, cannot exceed the maximum row size based upon the DB2 table space that the table data is assigned to.
|
If there is no appropriate mapping for a large object column, consider using column filtering on the article so that the column is not replicated. For more information, see Filtering Published Data.
-
When replicating SQL Server nchar and nvarchar to DB2 CHAR and VARCHAR, replication uses the same length-specifier for the DB2 type as for the SQL Server type. However, the data type length might too small for the generated DB2 table.
In some DB2 environments, a SQL Server char data item is not restricted to single-byte characters; the length of a CHAR or VARCHAR item must take this into account. You must also take into account shift in and shift out characters if they are needed. If you are replicating tables with nchar and nvarchar columns, you might need to specify a larger maximum length for the data type in a custom creation script. For information about specifying a custom creation script, see step 5 in the section "Configuring an IBM DB2 Subscriber" in this topic.