Results 1 to 4 of 4

Thread: Column for Primary Key

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Column for Primary Key

    SQL which column to select as primary key and why

    I have a table employee_account where only two coloums are there emp_id and acc_id. Which coloum i will make as primary key and why?


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Column for Primary Key

    U need to Set a data column as the primary key and guarantees that each record contains a unique value .
    Based on this rule decide yourself and add primary key

    Last edited by susarlasireesha; 01-09-2008 at 08:11 AM.

  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Column for Primary Key

    Deciding the mrimay key of the table entirely depends on the design and the end user requirments. Simply the field which you ant to be unique and not null should be the primary key . In your case select emp_Id as the primary jey. That is a better candidate for being the PK of the table.


  4. #4
    Junior Member
    Join Date
    Jan 2008
    Answers
    24

    Re: Column for Primary Key

    emp_id and acc_id should be unique and should not be null.so the requirement of primary key arises.if this table does not need any child records
    we can define primary key on either of the columns.if there is any need of child records follw belo procedure

    if we r using this as a parent table and we r having child table to this then we have to define the primary or unique key on the parent column and then foreign key on child column(in child table)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact