473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unique Index or PK ?

What are the advantages / disadvantages of having primary keys in lieu
of ordinary indexes ? If there are no foreign relationships defined, is
it better to have a two column index allowing reverse scans or primary
key ? Any performance or other benefits / issues ?

Many thanks.

Sep 1 '06 #1
4 5135

p175 wrote:
What are the advantages / disadvantages of having primary keys in lieu
of ordinary indexes ? If there are no foreign relationships defined, is
it better to have a two column index allowing reverse scans or primary
key ? Any performance or other benefits / issues ?

Many thanks.
Ignore, sorry . found a similar post .. siiigh DOH !!

Sep 1 '06 #2
"p175" <td******@hotmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
What are the advantages / disadvantages of having primary keys in lieu
of ordinary indexes ? If there are no foreign relationships defined, is
it better to have a two column index allowing reverse scans or primary
key ? Any performance or other benefits / issues ?

Many thanks.
Keep in mind that if you create the index first (before creating the PK),
then you can define reverse scans, cluster, etc and then when you create the
PK it will use the existing index with the attributes you want in the index.

Reverse Scans has "virtually" no overhead, and "may" have benefits in
certain situations. It really should be the default.
Sep 1 '06 #3

Mark A wrote:
Keep in mind that if you create the index first (before creating the PK),
then you can define reverse scans, cluster, etc and then when you create the
PK it will use the existing index with the attributes you want in the index.

Reverse Scans has "virtually" no overhead, and "may" have benefits in
certain situations. It really should be the default.
Now that I didn't know, so if I create an index, I can then alter the
table, adding a PK constraint that will assume the attributes of the
original index .. hmmm

Most useful, thanks.

Sep 1 '06 #4
"p175" <td******@hotmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
>
Now that I didn't know, so if I create an index, I can then alter the
table, adding a PK constraint that will assume the attributes of the
original index .. hmmm

Most useful, thanks.
A PK will create a unique index unless there is already a unique index on
the same columns, in which case no additional unique index is created. You
will get the following warning message:

Assume table TEST has no keys and no indexes to start with:

CREATE UNIQUE INDEX DB2INST1.TEST_IX1 ON DB2INST1.TEST (COL1 ASC);
DB20000I The SQL command completed successfully.

ALTER TABLE DB2INST1.TEST PRIMARY KEY (COL1);
SQL0598W Existing index "DB2INST1.TEST_IX1" is used as the index for the
primary key or a unique key. SQLSTATE=01550

In the DB2 catalog (SYCAT.INDEXES), the UNIQUERULE wil change from U
(Unique) to P (used for a Primary Key). If the PK is dropped, then the
unique index remains (only if you created it before the PK).
Sep 1 '06 #5

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

Similar topics

5
by: Laphan | last post by:
Hi All I know you can set a row to be unique, but I want expand on this in that I want the DB schema to only disallow an entry if the row isn't unique across 3 fields. Is it possible? My DDL...
3
by: June Moore | last post by:
Hi, I would like to add a unique index that consists of two fields in a table. e.g. tbl_A (field1,field2) -- field1 & field2 Indexed and combination must be Unique. Can anyone tell me the...
5
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
6
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...
5
by: aj | last post by:
DB2 WSE 8.1 FP5 Red Hat AS 2.1 What is the difference between adding a unique constraint like: ALTER TABLE <SCHEMA>.<TABLE> ADD CONSTRAINT CC1131378283225 UNIQUE ( <COL1>) ; and adding a...
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
3
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....
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.