SQL Tips - DB2
SQL Tips - DB2
Contributed By
Version Number
Anbu Cheliyan
1
Creation Date
28/05/2013
Page 1 of 10
Table of Contents
Page 2 of 10
Page 3 of 10
Page 4 of 10
Page 5 of 10
9 DB2 commands
9.1 Connecting to DB2 from unix
db2 connect to <DB_Name> user <User_Name> using <Password>
= DB2/LINUXX8664 9.7.4
= ETLUSER
= DEVDB
Check constraints
Column default values
Column comments
Foreign keys
Logged and compact option on BLOB columns
Distinct types
https://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=
%2Fsqlp%2Frbafycrttbllike.htm
Page 6 of 10
successfully.
successfully.
successfully.
successfully.
successfully.
COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11,COL12
,COL13,COL14,COL15,COL16,COL17,COL18,COL1
--------------------------------------------------,--------------,------,------------,---------------------------------,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------,-------------------------------------------------,---,--------------------,----------,------------------------,------------------,------------------------,----------------,---------------------,---------------------,---------------,--------------,-------------------100000033177673,1,E,645802771500327026860461290628.,01/01/0001,30/12/9999,1515
,1515,1595499,1595499,19/04/2013,19/04/2013,18/04/2013,
100000033177673,COM01,1,E,645802771500327026860461290628.,01/0
1/0001,30/12/9999,1519,1519,1596679,1596679,23/04/2013,23/04/2
013,22/04/2013,
Note: Varchar fields having spaces in it will be removed from
the output. Column Set_Id is blank in first row in above
output and -1 is value of third column Org_Id.
Page 7 of 10
TABSCHEMA
TABNAME
----------------------------------------ADW
ACCOUNT_MSISDN_HISTORY
1 record(s) selected.
$ db2 "select COLNAME from syscat.columns where COLNO=7 and
TABSCHEMA='ADW' and TABNAME='ACCOUNT_MSISDN_HISTORY'"
COLNAME
-----------------------------------------------------------------------------------------------------------------------------SERVICE_STATUS_ID
1 record(s) selected.
Page 8 of 10
17 DB2 directory
Database and server information is stored in the DB2
directories.
To list system database directory use the command db2
list database directory
$ db2 list database directory
System Database Directory
Number of entries in the directory = 5
Database 1 entry:
Database alias
Database name
Node name
Database release level
Comment
Directory entry type
Catalog database partition number
Alternate server hostname
Alternate server port number
=
=
=
=
=
=
=
=
=
UAT
UDB
UATNODE
c.00
=
=
=
=
=
=
=
=
=
DEVDB
UDB
DEVNODE
c.00
Remote
-1
Database 2 entry:
Database alias
Database name
Node name
Database release level
Comment
Directory entry type
Catalog database partition number
Alternate server hostname
Alternate server port number
Remote
-1
Page 9 of 10
=
=
=
=
=
=
DEVINT
=
=
=
=
=
=
DEVNODE
LOCAL
TCPIP
100.100.100.86
50000
Node 2 entry:
Node name
Comment
Directory entry type
Protocol
Hostname
Service name
LOCAL
TCPIP
100.100.100.85
50000
Page 10 of 10