473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

primary key index?

I have added primary key to my table using the 'ALTER TABLE' statement.
Now, is it mandatory for me to use the 'CREATE UNIQUE INDEX' on primary
key columns in order to enforce the primary key constraint?
I have a vague idea that unique indexes are automatically created when we
specify the primary key constraint.
Can somebody please confirm this?

Cheers,
San.
May 17 '06 #1
4 8139
"shsandeep" <sa**********@gmail.com> wrote in message
news:9a******************************@localhost.ta lkaboutdatabases.com...
I have added primary key to my table using the 'ALTER TABLE' statement.
Now, is it mandatory for me to use the 'CREATE UNIQUE INDEX' on primary
key columns in order to enforce the primary key constraint?
I have a vague idea that unique indexes are automatically created when we
specify the primary key constraint.
Can somebody please confirm this?

Cheers,
San.


If a unique index does not already exist on the columns of the primary key,
then DB2 will create such an index automatically when a PK is defined.

It is often desirable to first create the unique index yourself, and then
create the PK after that, because if DB2 creates the index automatically for
you it cannot be altered for various attributes such as percent free,
cluster, allow reverse scans, etc.
May 17 '06 #2
Thanks Mark, that definitely solves my query.
My 2nd question would be as follows:
I am using a 'system managed' tablespace in which the tables are being
created.
No specific indexspace has been specified.
Where would the indexes be created in such a case?

And is it ok to have this?

Cheers,
San.

May 17 '06 #3
"shsandeep" <sa**********@gmail.com> wrote in message
news:4c******************************@localhost.ta lkaboutdatabases.com...
Thanks Mark, that definitely solves my query.
My 2nd question would be as follows:
I am using a 'system managed' tablespace in which the tables are being
created.
No specific indexspace has been specified.
Where would the indexes be created in such a case?

And is it ok to have this?

Cheers,
San.


With SMS, the index will be placed in the same tablespaces as the table.
Since a given tablespace can only use one bufferpool, then the data and
index(es) will share the same bufferpool.

There is nothing wrong with this, especially if you have an OLTP system and
the bufferpool is relatively large compared to size of the tables and
indexes (resulting in a high bufferpool hit ratio).

If you have a data warehouse, and the it is not possible to have a high
bufferpool hit ratio because the amount of data is so large, it is sometimes
advisable to use DMS to place the index in a separate tablespace that can
use a different bufferpool, so that at least the bufferpool hit ratio can be
relatively high for the index(es).
May 17 '06 #4
If you do a select on the following views, SYSCAT.INDEXES and in
SYSCAT.TABCONST (those are views on the catalog tables) for that TABNAME,
you'll find rows that DB2 did indeed create a unique index on that table abd
a unique constraint for you.
Their names, as well as the constraint name will be like:
SYSIBM.SQLYYMMDDHHMMSSmmm where mmm is the millisecond.

HTH, Pierre.
--
Pierre Saint-Jacques
SES Consultants Inc.
514-737-4515
"shsandeep" <sa**********@gmail.com> a écrit dans le message de news:
9a******************************@loc...tdatabases.com...
I have added primary key to my table using the 'ALTER TABLE' statement.
Now, is it mandatory for me to use the 'CREATE UNIQUE INDEX' on primary
key columns in order to enforce the primary key constraint?
I have a vague idea that unique indexes are automatically created when we
specify the primary key constraint.
Can somebody please confirm this?

Cheers,
San.


May 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
17350
by: Tuhin Kumar | last post by:
Hi, Oracle give the error ORA-01418 when I try to do the following; Create unique index t1_pk on TABLE1(EntryId DESC) ; If the I try to add primary key Contraint using the above index t1_pk...
17
49791
by: Philip Yale | last post by:
I'm probably going to get shot down with thousands of reasons for this, but I've never really heard or read a convincing explanation, so here goes ... Clustered indexes are more efficient at...
4
10542
by: serge | last post by:
I ran into a table that is used a lot. Well less than 100,000 records. Maybe not a lot of records but i believe this table is used often. The table has 26 fields, 9 indexes but no Primary Key at...
6
2080
by: Bob Stearns | last post by:
I was under the impression that the primary key had to be a unique index. Since I usually create my primary indices before my primary keys, in order to get the indices in the same schema as their...
4
14412
by: deko | last post by:
I have a Make Table query that creates a fairly large table. The Make Table query populates the new table with one AutoNumber field (which is taken form another unrelated table as part of the...
8
31514
by: Paul Hunter | last post by:
I am new to databases and thus to Access. I have a situation where I am trying to figure out how to key some tables I am working with. Consider that I have a database of my own records which are...
9
3891
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
3
35298
by: vj_dba | last post by:
Hi Group, I have a Primary key in my table. It's clear Primary key wont allow duplicates, this primary key creates one index for retrival. Suppose if my table is having a Unique index also....
1
5307
by: mark_aok | last post by:
Hi all, I have a situation where I need to determine a specific table's primary key, and then output it. I have tried the Database Object, and the Record Object, but I've had no luck. ...
4
3117
by: codefragment | last post by:
Hi I thought that given a table with an index, primary key and clustered index any non clustered index look ups would go via the clustered index and the primary key is irrelevant? (sql server...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.