473,657 Members | 2,378 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 8255
"shsandeep" <sa**********@g mail.com> wrote in message
news:9a******** *************** *******@localho st.talkaboutdat abases.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**********@g mail.com> wrote in message
news:4c******** *************** *******@localho st.talkaboutdat abases.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.SQLYYMMD DHHMMSSmmm where mmm is the millisecond.

HTH, Pierre.
--
Pierre Saint-Jacques
SES Consultants Inc.
514-737-4515
"shsandeep" <sa**********@g mail.com> a écrit dans le message de news:
9a************* *************** **...atabase s.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
17387
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 as below: ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId) USING INDEX t1_pk;
17
49814
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 returning large numbers of records than non-clustered indexes. Agreed? (Assuming the NC index doesn't cover the query, of course) Since it's only possible to have one clustered index, why is this almost always used for the primary key, when by...
4
10556
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 all! There are no table relationships defined in this database, no Natural keys, only Surrogate keys in the database. 1- Maybe an odd question but is it normal to have 1/3 of the table's fields as indexes? Is this a valid question or it really
6
2090
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 tables, it is possible , by error, to create such an index without the unique attribute. DB2 UDB 8.1.5 Linux uses such an index for the primary key anyway, thus losing the unique property of the primary key. Is this a bug or a feature, i.e. a...
4
14419
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 query). I want to make the AutoNumber field the Primary Key: DoCmd.OpenQuery "qryXL_To" ' this is the make table query DoCmd.RunSQL "CREATE UNIQUE INDEX idxTxAcct ON tblXL_To (TxAcct_ID)" This seems to work okay, but it does not create a...
8
31533
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 invoices I work on. These invoices are from four companies with their own invoice numbers. So, I cannot key by invoice number because there is a likelihood of invoice numbers duplicated by different companies. The records in this table of joined...
9
3904
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 eg: area.txt, school.txt, students.txt.... and so on (ok?!?) now, 1. area code used in the school.txt must be defined in the area.txt (Primary key in area => area_code defined in area.txt & Foreign key on school => area_code defined in...
3
35383
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. Then what is the exact difference between the Primary key and the Unique index? Also which on data retrival..internally it uses the Primary key index
1
5333
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. Ideally there would be something like,
4
3130
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 2000). A colleague has said that the primary key should be the clustered index because all index lookups will go via the primary key. Is this right? I thought the primary key was nothing more than a constraint on what data can be entered into the...
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.