Adsense

Tuesday, October 28, 2014

Create Database in DB2 with Unicode (UTF-8) support - Command

By default, in DB2, databases are created in the code page of the application which creates them. In windows, Simply create a database with the following command

db2 create db employee
            - where employee is the database name.

By default employee database is created with the code page 1252 where as code page 1208 will have utf-8 support. You can see the codeset of a database by giving the following command.

In Windows :  db2 get db cfg for employee | find "code"
In Linux :   db2 get db cfg for employee | grep -i  code

Database code page = 1252
Database code set = IBM-1252


 You can also run the following query to get the code-page.

db2 connect to dbname

db2 "Select codepage from syscat.datatypes where typename = 'VARCHAR'"

which returns 1252


We can create the database with unicode (UTF-8) support by the following ways

1) We can create our database from a Unicode (UTF-8) client (for eg. the UNIVERSAL locale of AIX or set DB2CODEPAGE registry variable on the client to 1208)

2) We can explicitly specify CODESET as "UTF-8" with valid TERRITORY code supported by DB2 Universal Database.

To create a Unicode database named "emp_utf" with the territory code for the US, give the following command.

db2 create db emp_utf using codeset utf-8 territory us collate using system

Now again check the code page with the command

db2 get db cfg for emputf |  | find "code" 

which will give following output

Database code page = 1208
Database code set = utf-8

Note : When a Unicode database is created, CHAR, VARCHAR, LONG VARCHAR, and CLOB data are stored in UTF-8 form, and GRAPHIC, VARGRAPHIC, LONG VARGRAPHIC, and DBCLOB data are stored in UCS-2 big-endian form.

0 comments:

Post a Comment