Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Duplicate entries for same primary key

Former Member
0 Likes
3,817

Hi,

I am facing problem to insert 2 or more than 2 entries for same PRIMARY KEY in the database table.

As I know that we can’t do that. But Client has given me the XL sheet which contains 2 entries for same primary key. How can it be done? Please let me know how can I insert 2 data for same primary key in database table.

Waiting for your answers.

Thanks in advance.

Regards,

Prasanna

Hi,

I am facing problem to insert 2 or more than 2 entries for same PRIMARY KEY in the database table.

As I know that we can’t do that. But Client has given me the XL sheet which contains 2 entries for same primary key. How can it be done? Please let me know how can I insert 2 data for same primary key in database table.

Waiting for your answers.

Thanks in advance.

Regards,

Prasanna

7 REPLIES 7
Read only

Former Member
0 Likes
1,970

Hi Vidya,

Strictly speaking we cannot do that. That is the concept of primary key to have only one unique key. Is that standard table ? if it is so then check whether it has secondary keys along with the primary key which is calle das composite key, If this is the case then the database table will check for the entire composite key.

Let me know whether you understood this or not

Reward points if it is helpful.

Regards,

Kiran I

Read only

Former Member
0 Likes
1,970

Hi ,

This is not possible , beacuse it ruins the basic purpose of having a primary key if we can have multiple entries with the same primary key.

Discuss the same with the client , may be this can be an error in the excel file.

Regrads

Arun

Read only

Former Member
0 Likes
1,970

There may be 2 primary keys in that table , though one of them is duplicated the other one may be ubique

Primary key1  Primary key2

  111                  abc
  222                  abc

Read only

Former Member
0 Likes
1,970

You can't rely on the spreadsheet supplied by the customer. You have to look at the data (SE11 or SE16).

Rob

Read only

VinayPrasad_PM
Product and Topic Expert
Product and Topic Expert
0 Likes
1,970

Hi,

Just make one more unique field as a part of primary key. That will solve your problem. (If you can do that?)

Example

Table1

F1(pk) -


F2(pk)------ F3 -


F4

1 -


1 -


1 -


A

1 -


1 -


2 -


B

You can make field F3 also part of the primary key (If that’s possible).

Or

Data may be wrong. Primary keys in RDBMS are based on set theory. By definition set is a collection of unique elements. So it cannot be possible

Regards,

Vinay

Read only

Former Member
0 Likes
1,970

Hi,

You can achieve this .... All you have to do is to add a new field (a Sequence Number ) to the table. This number will be incremented for each duplicate primary keys. For example....

Consider the excel file has duplicate entries 3 primary keys. Now you add a new field named Sequence Number in your DB Table.....

When you load the data into Database...then the records will look like this...

Key1 Key2 Key3 Seq

A B C 1

A B C 2

A B D 1

A B D 2

A C D 1

A C E 1

and so on...

I hope this solves your purpose.....

Whenever there are duplicate entries, such as the one mentioned in your scenario, then a new field can be added in Database. This field acts like a count or sequence number.... Thus you can maintain unique records.

Regards,

Vara

Regards,

Vara

Read only

Former Member
0 Likes
1,970

Hi Vidya,

Without adding additional fields into the DB Table, this would not be possible.

Regards,

Ramki.