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?
Printable View
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?
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
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.
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)