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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Create a new Primary Key on survey table

Create a new Primary Key on survey table

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 4 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.
  • L Offline
    L Offline
    learning_new
    wrote on last edited by
    #1

    I have a survey table where people were asked up 7 question and I'm trying to figure out the best way to assign a primary key in sql. here how it looks like. key surveyid questionid answid questions answer ed45894 1 3 1 when was the last time you bought soda 1 week ago ed45894 1 7 2 How many live in your house 4 ed45894 1 4 5 do you children in your house Yes ed45894 1 2 7 do you use coupon while shopping No fs45895 1 3 4 when was the last time you bought soda yesterday fs45895 1 7 2 How many live in your house 1 fs45895 1 4 5 do you children in your house Yes fs45895 1 2 7 do you use coupon while shopping No

    N L D 3 Replies Last reply
    0
    • L learning_new

      I have a survey table where people were asked up 7 question and I'm trying to figure out the best way to assign a primary key in sql. here how it looks like. key surveyid questionid answid questions answer ed45894 1 3 1 when was the last time you bought soda 1 week ago ed45894 1 7 2 How many live in your house 4 ed45894 1 4 5 do you children in your house Yes ed45894 1 2 7 do you use coupon while shopping No fs45895 1 3 4 when was the last time you bought soda yesterday fs45895 1 7 2 How many live in your house 1 fs45895 1 4 5 do you children in your house Yes fs45895 1 2 7 do you use coupon while shopping No

      N Offline
      N Offline
      Nathan Minier
      wrote on last edited by
      #2

      You're highly unlikely to overrun an int for surveys.

      "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

      1 Reply Last reply
      0
      • L learning_new

        I have a survey table where people were asked up 7 question and I'm trying to figure out the best way to assign a primary key in sql. here how it looks like. key surveyid questionid answid questions answer ed45894 1 3 1 when was the last time you bought soda 1 week ago ed45894 1 7 2 How many live in your house 4 ed45894 1 4 5 do you children in your house Yes ed45894 1 2 7 do you use coupon while shopping No fs45895 1 3 4 when was the last time you bought soda yesterday fs45895 1 7 2 How many live in your house 1 fs45895 1 4 5 do you children in your house Yes fs45895 1 2 7 do you use coupon while shopping No

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        learning_new wrote:

        trying to figure out the best way to assign a primary key in sql

        There is only one way to do so; you find the column or columns that uniquely identify a single row in the collection. If you are having trouble with it, you're not normalizing. Your table should be in 3NF; or in short, you want the key, the whole key, and nothing but the key. Codd's law, look it up.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        1 Reply Last reply
        0
        • L learning_new

          I have a survey table where people were asked up 7 question and I'm trying to figure out the best way to assign a primary key in sql. here how it looks like. key surveyid questionid answid questions answer ed45894 1 3 1 when was the last time you bought soda 1 week ago ed45894 1 7 2 How many live in your house 4 ed45894 1 4 5 do you children in your house Yes ed45894 1 2 7 do you use coupon while shopping No fs45895 1 3 4 when was the last time you bought soda yesterday fs45895 1 7 2 How many live in your house 1 fs45895 1 4 5 do you children in your house Yes fs45895 1 2 7 do you use coupon while shopping No

          D Offline
          D Offline
          David Mujica
          wrote on last edited by
          #4

          Can you explain what these columns are ? Looks like you have enough data to make a primary key, but understanding the data would lead to a suggestion. :java:

          L 1 Reply Last reply
          0
          • D David Mujica

            Can you explain what these columns are ? Looks like you have enough data to make a primary key, but understanding the data would lead to a suggestion. :java:

            L Offline
            L Offline
            learning_new
            wrote on last edited by
            #5

            Thanks David. I was able to figure out.

            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