Solved

multiple unique columns in a table

Posted on 2011-09-16
8
382 Views
Last Modified: 2012-05-12
can we have multiple unique columns in a table. I was not clear on this concept. Please advise. thanks in advance
0
Comment
Question by:gudii9
8 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36552810
you can have multiple unique columns in a table - there is nothing that may prevent it
0
 
LVL 47

Accepted Solution

by:
for_yan earned 125 total points
ID: 36552821
Let's say you have the table of patients of the hospital - they may have their own id for each patient , but they may have a column for insusrance id and those
may be also be unique - certainly no problem with that
0
 
LVL 37

Assisted Solution

by:momi_sabag
momi_sabag earned 125 total points
ID: 36552830
you can have as many unique constraint you want on a table
a unique constraint verify that a column or set of columns have unique values in every row in a table
0
 
LVL 21

Assisted Solution

by:Amitkumar Panchal
Amitkumar Panchal earned 125 total points
ID: 36553738
Yes, You can have unique constraint on the all fields of the table. Only thing is that if the column having unique constraint must contains a unique value in that field across the table. However, the field contains a null (no value) value in it, so multiple null values are allowed in the field having a  unique constraint.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 125 total points
ID: 36553894
Hi gudi,

The easiest way to enforce multiple unique columns in a table is to put a unique index on each of the columns.  

In fact, if you have a significant amount of data in the table it will be almost imperative to have these columns indexed as every insert or update will need to verify that the new data is unique within the column.  Without indexes on these column a full table scan will be required just to insert a new row!


Good Luck,
Kent
0
 
LVL 7

Author Comment

by:gudii9
ID: 36718886
How to put  unique index on each column
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36718899
you can create index for any column or you can impose unique constraint on each colimn -
thes are different things
0
 
LVL 45

Expert Comment

by:Kdo
ID: 36718913
Hi gudi,

You'll need to add the index or constraint for each column that must be unique.

CREATE UNIQUE INDEX idx0001 ON mytable (column1);
CREATE UNIQUE INDEX idx0002 ON mytable (column2);
etc....



Kent
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Clone Oracle 12c Database 5 42
Fastest way to replace data in Oracle 5 50
Query to identify changes between rows of two tables 8 37
help on oracle query 5 30
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now