View previous topic :: View next topic
|
Author |
Message |
pingte
Active User
Joined: 03 Dec 2005 Posts: 120 Location: india
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
pingte
Active User
Joined: 03 Dec 2005 Posts: 120 Location: india
|
|
|
|
Can't there be a DB2 table without primary key? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
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 |
|
|
|