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 10 14696
"Laurence" <wo**********@h otmail.com> wrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com... 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
A unique constraint will automatically created a unique index, unless a
unique index already exists on the same columns.
A unique constraint must only contain columns that are defined as not null
(like a PK). A unique index can have a nullable column (but null values are
not ignored and they are counted in determining uniqueness).
A foreign key on a child table can reference a unique constraint on a parent
table (and obviously it can also reference a PK on a parent table).
"Mark A" <no****@nowhere .com> wrote in message
news:es******** *************** *******@comcast .com... A unique constraint will automatically created a unique index, unless a unique index already exists on the same columns.
A unique constraint must only contain columns that are defined as not null (like a PK). A unique index can have a nullable column (but null values are not ignored and they are counted in determining uniqueness).
A foreign key on a child table can reference a unique constraint on a parent table (and obviously it can also reference a PK on a parent table).
Correction, first sentence should read:
A unique constraint will automatically create a unique index, unless a
unique index already exists on the same columns.
> A unique index can have a nullable column (but null values are
not ignored and they are counted in determining uniqueness).
So, does it mean the rows in the same column only can have one NULL
value? or otherwise the violation rule will be fired?
"Laurence" <wo**********@h otmail.com> wrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com... A unique index can have a nullable column (but null values are not ignored and they are counted in determining uniqueness).
So, does it mean the rows in the same column only can have one NULL value? or otherwise the violation rule will be fired?
Yes. On DB2 for z/OS their is an option when creating the unique index so
that it will ignore nulls, but this feature is not available on DB2 for
Linux, UNIX, Windows.
Laurence wrote: 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?
A unique constraint is a logical element in a data model.
DB2 uses a unique index as the physical implementation of that.
"Ian" <ia*****@mobile audio.com> wrote in message
news:44******** **@newsfeed.slu rp.net... A unique constraint is a logical element in a data model.
DB2 uses a unique index as the physical implementation of that.
A Unique Constraint is a physical element of DB2 DDL. It has some special
characteristics that differ from a unique index that have been noted earlier
in this thread.
Mark A wrote:
"Ian" <ia*****@mobile audio.comwrote in message
news:44******** **@newsfeed.slu rp.net...
>A unique constraint is a logical element in a data model.
DB2 uses a unique index as the physical implementation of that.
A Unique Constraint is a physical element of DB2 DDL. It has some special
characteristics that differ from a unique index that have been noted earlier
in this thread.
A unique constraint <primary key. The OP asked what the difference
between a unique constraint and a unique index was, but nothing about
a primary key.
You can create a unique index on a table, but you there is no
requirement have to add a unique constraint to the table as well.
DB2 will continue to work fine, and will enforce the uniqueness just
the same.
"Ian" <ia*****@mobile audio.comwrote in message
news:44******** @newsfeed.slurp .net...
>
A unique constraint <primary key. The OP asked what the difference
between a unique constraint and a unique index was, but nothing about
a primary key.
You can create a unique index on a table, but you there is no
requirement have to add a unique constraint to the table as well.
DB2 will continue to work fine, and will enforce the uniqueness just
the same.
I never said that a unique constraint was the same as a primary key. But one
of the differences between a unique constraint and unique index is that a
foreign key on another table can refer to a unique constraint, even if it is
not the primary key.
Mark A wrote:
I never said that a unique constraint was the same as a primary key. But one
of the differences between a unique constraint and unique index is that a
foreign key on another table can refer to a unique constraint, even if it is
not the primary key.
Mark,
That is a true statement - you can't define a foreign key without a
constraint (unique or primary key).
Regardless, I still hold that constraints are purely logical entities.
There are no physical manifestations of them (other than some entries in
the system catalog).
Unique indexes are the _physical_ implementation that DB2 uses to
enforce uniqueness (because it's a lot more efficient than trying to
scan an entire table to determine if a value already exists :-). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KULJEET |
last post by:
foreign key also refer to unique constraint.
(GREAT...)
1.then table that containt unique constraint act as master table?????
2.IS unique constraint will replace with primary key??
3.Is unique constraint gives all fuctionality as primary key constraint???
thanks
kuljeet pal singh
|
by: Agoston Bejo |
last post by:
I want to enforce such a constraint on a column that would ensure that the
values be all unique, but this wouldn't apply to NULL values. (I.e. there
may be more than one NULL value in the column.)
How can I achieve this?
I suppose I would get the most-hated "table/view is changing,
trigger/function may not see it" error if I tried to write a trigger that
checks the uniqueness of non-null values upon insert/update.
|
by: Mansoor Azam |
last post by:
When I add a unique key constraint to column in SQL 6.5 why does it also
create an index. e.g. In the table subaccounts I added a unique key
constraint for the column login and SQL creates an index with the name
UQ_SubAccounts_2__19 (UKC).
Does this also mean that there is no need to create an index for this
column?
thx
|
by: Kamil |
last post by:
Hello
What should I use for better perfomance since
unique constraint always use index ?
Thanks
Kamil
|
by: Dave |
last post by:
Can you create a unique constraint on multiple columns, or does it have
to be implemented as a unique index?
If possible can someone please post some sample code?
Thanks,
| |
by: Thomas LeBlanc |
last post by:
Does a Unique Constraint build a unique index?
What is the difference?
Thanks,
Thomas LeBlanc
_________________________________________________________________
Get a FREE computer virus scan online from McAfee.
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
|
by: Prince Kumar |
last post by:
Is there any way I can define an Unique constraint or unique index
which allows more than one null values for the same column combination
in DB2?
ie, If my index is defined on (col3, col4) where both columns allow
nulls, I want col3 + col4 to be unique, if one or both the columns
have values. If both columns have nulls, it should allow more than one
such rows.
ex,
|
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 unique index like:
|
by: D.Stone |
last post by:
Hi, I'm getting hung up on a trivial schema change - I need to make a
column accept only null or unique values and Books Online avers 'what
you need is a UNIQUE constraint'. Fine.
I've tried doing this interactively both in Access and in Enterprise
Manager; I've deleted the column and recreated it; I've written a T-
SQL script to ALTER TABLE. All fail with messages along the lines of:
- Unable to create index 'IX_Student'.
ODBC error:...
|
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...
|
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,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |