Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Is it possible for a primary key to have same values?

Posted on 2011-10-19
4
Medium Priority
?
338 Views
Last Modified: 2012-06-27
Hi there;

I got a table having columns having 2 PKs.

So that is it possible to have same values for a column for the given row?

Table
ColA ColB
1        2
2        3
3        2
4        4
4        5

For ColA; 4 4 and 4 5, so ColA can have 4, even he is a PK?
Same for ColB 1 2 and 3 2 ?

Kind regards
0
Comment
Question by:jazzIIIlove
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:VipulKadia
VipulKadia earned 668 total points
ID: 36991822
If your table has both the columns as Primary key (i.e. Composite key) then above data is valid as the combination of both the column don't have same data.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1332 total points
ID: 36991899
>I got a table having columns having 2 PKs.

actually, there is often a misunderstanding in regards to "primary key".
you can only have 1 primary key constraint per table, but that constraint can cover 1 or several columns, which hence all together build up the primary key "value". so, the values of the different columns are not to be taken "apart", but together to form the primary key

you CAN have several "unique constraints", aside of the primary key constraint, covering other column combinations.
this is usually done on "candidate keys" and/or "natural keys"

so, to answer your question: this is perfectly ok
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 36992109
Before finalizing the question, ok, angelll, where are do you put composite key definition of VipulKadia in your comment?

Kind regards.
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1332 total points
ID: 36992703
it goes here:
>but that constraint can cover 1 or several columns
so, we do agree on the status that what you show is perfectly valid
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

578 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