By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Duplicate data

P: 20
I would like to make sure there are no duplicate data entries in my Oracle 9i table (called MainTable) which has an Id field that is the primary key, ValData with a varchar data type, Fid and Fid2 are number data types.

Expand|Select|Wrap|Line Numbers
  1. Id   ValData   Fid   Fid2
  2. 1    abc         34    2
  3. 2    efg          23    34
  4. 3    zeo         25    43
  5.  
Sometimes someone can enter a duplicate ValData, Fid and Fid2 and it will end up like this:

Expand|Select|Wrap|Line Numbers
  1. Id   ValData   Fid   Fid2
  2. 1    abc          34    2
  3. 2    efg           23    34
  4. 3    zeo          25    43
  5. 4    zeo          25    43
  6.  

What constraints or restrictions can I place on the MainTable where it will never allow a duplicate entry into the table?
I would like to do this somehow in the database. If someone tries to enter a duplicate I should get a error message or something to indicate an attempt to enter duplicate data.

Please advise if this is possible?
Oct 21 '07 #1
Share this Question
Share on Google+
1 Reply


amitpatel66
Expert 100+
P: 2,367
I would like to make sure there are no duplicate data entries in my Oracle 9i table (called MainTable) which has an Id field that is the primary key, ValData with a varchar data type, Fid and Fid2 are number data types.

Expand|Select|Wrap|Line Numbers
  1. Id   ValData   Fid   Fid2
  2. 1    abc         34    2
  3. 2    efg          23    34
  4. 3    zeo         25    43
  5.  
Sometimes someone can enter a duplicate ValData, Fid and Fid2 and it will end up like this:

Expand|Select|Wrap|Line Numbers
  1. Id   ValData   Fid   Fid2
  2. 1    abc          34    2
  3. 2    efg           23    34
  4. 3    zeo          25    43
  5. 4    zeo          25    43
  6.  

What constraints or restrictions can I place on the MainTable where it will never allow a duplicate entry into the table?
I would like to do this somehow in the database. If someone tries to enter a duplicate I should get a error message or something to indicate an attempt to enter duplicate data.

Please advise if this is possible?

If you want all the columns to be unique, then create a composite key on the table.

In case if you want to allow NULL values, then create a UNIQUE key on other three columns so that it will accept null values also!!
Oct 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.