Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How do i allow duplicates in my primary key?

How do i allow duplicates in my primary key?

Scheduled Pinned Locked Moved Database
questionbusiness
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ap_ple
    wrote on last edited by
    #1

    Flight_ID Passenger_ID Seat_Number Seat_Cost Seat_Class 1 3 j15 $112.00 Business 2 5 K16 $38.00 Economy 3 4 A12 $85.00 Economy 4 2 B05 $40.00 Economy 5 1 C08 $85.00 Economy 6 5 B12 $85.00 Economy 8 7 K17 $42.00 Economy 9 6 L25 $125.00 Business I need to be able to allow duplicated in the Flight_ID which is the primary key so i can allow more passengers to be able to "fly" on that flight :confused: iD

    A B M V 4 Replies Last reply
    0
    • A ap_ple

      Flight_ID Passenger_ID Seat_Number Seat_Cost Seat_Class 1 3 j15 $112.00 Business 2 5 K16 $38.00 Economy 3 4 A12 $85.00 Economy 4 2 B05 $40.00 Economy 5 1 C08 $85.00 Economy 6 5 B12 $85.00 Economy 8 7 K17 $42.00 Economy 9 6 L25 $125.00 Business I need to be able to allow duplicated in the Flight_ID which is the primary key so i can allow more passengers to be able to "fly" on that flight :confused: iD

      A Offline
      A Offline
      Alsvha
      wrote on last edited by
      #2

      You can't have duplicate primary keys, it kind of defeats the entire purpose of having it as a primary key. A primary key needs to be unique. What you can do instead is make a combined primary key consisting of multiple columns or revisit whether you need/want that column as a primary key to begin with. Considering the snippet of your table you have posted, I would think that a combined key of Flight_ID and Passenger_ID (A specific passenger on a specific flight should all things equal be unique.) would be the best way to go.

      --------------------------- Blogging about SQL, Technology and many other things

      1 Reply Last reply
      0
      • A ap_ple

        Flight_ID Passenger_ID Seat_Number Seat_Cost Seat_Class 1 3 j15 $112.00 Business 2 5 K16 $38.00 Economy 3 4 A12 $85.00 Economy 4 2 B05 $40.00 Economy 5 1 C08 $85.00 Economy 6 5 B12 $85.00 Economy 8 7 K17 $42.00 Economy 9 6 L25 $125.00 Business I need to be able to allow duplicated in the Flight_ID which is the primary key so i can allow more passengers to be able to "fly" on that flight :confused: iD

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        To allow adding multiple passagers on one flight then make combination of primary key with Flight_id and Passager_ID


        I Love T-SQL "Don't torture yourself,let the life to do it for you."

        1 Reply Last reply
        0
        • A ap_ple

          Flight_ID Passenger_ID Seat_Number Seat_Cost Seat_Class 1 3 j15 $112.00 Business 2 5 K16 $38.00 Economy 3 4 A12 $85.00 Economy 4 2 B05 $40.00 Economy 5 1 C08 $85.00 Economy 6 5 B12 $85.00 Economy 8 7 K17 $42.00 Economy 9 6 L25 $125.00 Business I need to be able to allow duplicated in the Flight_ID which is the primary key so i can allow more passengers to be able to "fly" on that flight :confused: iD

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Your table design sucks - big time. You should have the following tables to get this data Flight - FlightNo Passenger - PassengerID Seat - SeatNo Cost - CostID Transaction TranID FlightNo PassengerID SeatNo CostID Your primary key Flight_ID is NOT the primary key for the transaction table as you are attempting to make it! Recommendation you REALLY need to get a book on data structuring before adventuring into this area, you will save yourself months of heartache. Even if you get this working for flight 1 (it is possible for 1 flight) as soon as you add another flight or another plane design or want to change the cost of a class of seats you are in trouble. GET A DESIGN BOOK - READ IT.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • A ap_ple

            Flight_ID Passenger_ID Seat_Number Seat_Cost Seat_Class 1 3 j15 $112.00 Business 2 5 K16 $38.00 Economy 3 4 A12 $85.00 Economy 4 2 B05 $40.00 Economy 5 1 C08 $85.00 Economy 6 5 B12 $85.00 Economy 8 7 K17 $42.00 Economy 9 6 L25 $125.00 Business I need to be able to allow duplicated in the Flight_ID which is the primary key so i can allow more passengers to be able to "fly" on that flight :confused: iD

            V Offline
            V Offline
            Vinay Dornala
            wrote on last edited by
            #5

            Hi, Composite key on Fight_ID and Passenger_ID that might cause same problem in following scenario. If the same passenger let say 101 is booking fight 1001 for two different dates. 101 1001 $112.00 Business 5/3/2008 101 1001 $38.00 Business 7/3/2008 So best sol is to add identity column ( i. e TransactionID) in this case.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups