Showing posts with label DB2 table is incomplete. Show all posts
Showing posts with label DB2 table is incomplete. Show all posts

The definition of the DB2 table is incomplete

DBA's love creating DB2 objects, not sure how many DBA's have faced '' The definition of the table is incomplete " and wondered why ( at least for a moment ) ?


A simple DB2 tablespace is created in an existing database followed by a table with ' n ' number of columns. The application needs a primary key to be created on the first column. The DBA embeds the primary key syntax within the create table statement as shown below :


Primary_Key

If you execute the above syntax ( provided you have the database and tablespace ) there shouldn't be any error - Peice of cake ? Possibly the simplest of requests one can ever work on. Looks like nothing is missed ? Let's confirm that.


Issue a SQL query against the newly created table - SELECT COUNT(*) FROM USER01.TEST_TABLE ;


Error message :

SQL -540

I thought my table definition was complete. Where is this incomplete definition coming from ?


Resolution :


Primary key follows with a UNIQUE Index on the table. If you create a primary key and miss out on creating an unique index on the column comprising the primary key - your DB2 table is rendered incomplete and unusable.