IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Change in table definition?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Thu Jan 01, 2009 4:26 pm
Reply with quote

I have a Db2 table - TABL1

It has 2 columns - X and Y , wherin X is defined as primary key.

Now the table definition has to change.

X will no longer be the primary key;
AND
X needs to be non unique - So what sort of key should X be defined as?

Note: There will be no primary key in this table.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 01, 2009 4:43 pm
Reply with quote

Hello,

Define a new column Z to be the primary key that will be automatically generated as rows are inserted.

Quote:
So what sort of key should X be defined as
Non-unique.

Quote:
Note: There will be no primary key in this table.
I believe there will. . .
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Fri Jan 02, 2009 8:26 am
Reply with quote

Can't there be a DB2 table without primary key?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 02, 2009 9:08 am
Reply with quote

Hello,

From the manual:
Quote:
1.5.2 Primary keys

A primary key is a unique key that is a part of the definition of a table. A table can have only one primary key, and the columns of a primary key cannot contain null values. Primary keys are optional and can be defined in CREATE TABLE or ALTER TABLE statements.

The unique index on a primary key is called a primary index. When a primary key is defined in a CREATE TABLE statement, the table is marked unavailable until the primary index is created by the user unless the CREATE TABLE statement is processed by the schema processor. In that case, DB2 automatically creates the primary index.

When a primary key is defined in an ALTER TABLE statement, a unique index must already exist on the columns of that primary key. This unique index is designated as the primary index.


The answer is more to do with your organizaton's database standards. Many require a primary key for every table.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Fri Jan 02, 2009 1:58 pm
Reply with quote

Pingte,

In our organization, unfortunately, we have many tables without primary key. If we need to compare this tables data, we do it on record by record (which is a very bad process). Everything depends on the data base design and designers.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top