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

Posted on 2011-10-19
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?

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
Question by:jazzIIIlove
    LVL 8

    Assisted Solution

    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.
    LVL 142

    Accepted Solution

    >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
    LVL 12

    Author Comment

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

    Kind regards.
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    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

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now