If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > Database Server Software > DB2 > How find constraints on a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 182
How find constraints on a table

Is there any view/table that gives me information in db2 to find the constraints defined on a table?... like user_constraints & user_cons_columns in oracle..

TIA
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,722
If you use the db2look command (a DB2 command, not SQL) with the e parameter, you will see the table DDL with constraints. See the Command Reference manual.

If you want to look at the DB2 catalog, look at Appendix D in of the SQL Manual Volume 1, where the DB2 system catalog tables are described. It's probably a bit more complex than Oracle because different constraints may be in different catalog tables, but I assume it is all there somewhere.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Nov 2002
Location: vienna
Posts: 9
Re: How find constraints on a table

assumeing that you are using DB2 for Unix,Linux,Windows or OS/2:

SYSCAT.TABCONST:
CONSTNAME VARCHAR(18)
TABSCHEMA VARCHAR(128)
TABNAME VARCHAR(128)
DEFINER VARCHAR(128)
TYPE CHAR(1) ( F= FOREIGN KEY, K=CHECK, P=PRIMARY KEY, U=UNIQUE)
REMARKS VARCHAR(254)

Each row represents a table constraint of type CHECK, UNIQUE, PRIMARY KEY or FOREIGN KEY

Last edited by sandner; 09-18-03 at 01:49.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,722
That gives the name of the constraint, but not the definition.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 182
Quote:
Originally posted by Marcus_A
If you use the db2look command (a DB2 command, not SQL) with the e parameter, you will see the table DDL with constraints. See the Command Reference manual.

If you want to look at the DB2 catalog, look at Appendix D in of the SQL Manual Volume 1, where the DB2 system catalog tables are described. It's probably a bit more complex than Oracle because different constraints may be in different catalog tables, but I assume it is all there somewhere.
Ya, thanks that was useful. However, using syscat tables is not possible for non-privileged users.

Cheers
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Nov 2002
Location: vienna
Posts: 9
Hallo Markus

This is a table that gives information in db2 to find the constraints defined on a table
That's the question
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,722
No one has select access to any table unless someone grants it to them. Ask your DBA for select access to the catalog tables.
Reply With Quote
  #8 (permalink)  
Old
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,649
The following tables also give you constraint info :

1) SYSCAT.CHECKS - For Check Constraints - TEXT column gives the check constraint definition

2) SYSCAT.KEYCOLUSE - Gives info on Primary Key and Foreign Key Constraints

As Marcus indicated, you'll have to contact your administrator for SELECT permission

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On