Tuesday, June 24, 2008

DB2

List all the tables in a database (Excluding system-defined tables)
In DB2, system-defined tables are created in schemas that start with 'SYS'.
SELECT  TABSCHEMA, TABNAME, TYPE, COLCOUNT,KEYCOLUMNS, KEYINDEXID, KEYUNIQUE 
FROM SYSCAT.TABLES
WHERE TABSCHEMA NOT LIKE 'SYS%' AND TYPE = 'T'

db2 list tables


List all the columns in a given table
SELECT  TABSCHEMA, TABNAME, COLNO, COLNAME,TYPENAME, LENGTH, DEFAULT, IDENTITY, HIDDEN
FROM SYSCAT.COLUMNS
WHERE TABSCHEMA NOT LIKE 'SYS%' AND TABNAME = 'TABLE_NAME'


List all the indexes available for a given table
SELECT  INDNAME, DEFINER, TABSCHEMA, TABNAME, COLNAMES, COLCOUNT, UNIQUERULE, INDEXTYPE 
FROM SYSCAT.INDEXES
WHERE TABSCHEMA NOT LIKE 'SYS%' AND TABNAME = 'TABLE_NAME'


list all types
select typename from syscat.datatypes


db2 date and timestamp
The default format used for dates is determined by the territory code of the database. Let's say the default format is 'yyyy-mm-dd'.
DATE('2008-01-30')
TIMESTAMP('2007-11-30-00.00.00')
For more detail, you can refer to this article.

No comments:

Post a Comment