What is the difference between the Primary and Foreign key?
Answers were Sorted based on User's Feedback
Answer / dhirendra
Primary Key: This is a constraint which is always unique &
not null.
Foreign Key: This is a constraint which is just opposite to
Primary key. It can be not Null & can accept duplicate value
as well. Foreign key points to same table's primary key or
another table's primary key to make a relationship.
Is This Answer Correct ? | 12 Yes | 2 No |
Answer / suresh babu
Primary key and foreign key both are constraints.
Primary key:We can create only one primary key for a
table,which never allows the repeated or duplicate values
and null values.The index will be created when defining a
primary key.And primary key is used to make a relation
between more than one tables.
Foreign key:It allows the duplicate and null values.if we
want to make a relation between two tables,the parent table
column must have primary column and child table column
called foreign key.
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / slokh
Primary key does not contain NULL or duplicate values.
whereas Foreign key accepts duplicate values but not null
values.
Primary key states the Entity integrity constraint, which
says that every row in a table is unique.
Foreign key states the referential integrity constraint,
that says that you can only insert values that is present
in the primary of the parent table.
Is This Answer Correct ? | 8 Yes | 2 No |
Answer / dhirendra
Primary Key: This is a constraint which is always unique &
not null.
Foreign Key: This is a constraint which is just opposite to
Primary key. It can be not Null & can accept duplicate value
as well. Foreign key points to same table's primary key or
another table's primary key to make a relationship.
Is This Answer Correct ? | 3 Yes | 1 No |
Primary key uniquely identified a record in a table and dont have null values. Also when we create primary key an index is automatically created for primary key.
On the other hand foreign key is used for referential integrity, foreign key can points to primary key in other table and moreover index is not created for foreign key.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dinesh kumar
Primary key will checks for the Duplicates.
Can hold only one primary key for a single table.
Foreign key will be referred from the Primary/unique Key
constraint. Hold even null values in it.
Is This Answer Correct ? | 0 Yes | 0 No |
Can function return multiple values in sql?
Which tcp/ip port does sql server run on? How can it be changed? : Sql dba
What is java sql driver?
what is innodb? : Sql dba
Is it possible to link two groups inside a cross products after the cross products group has been created?
What is the difference between local variables and global variables?
Is like operator in sql case sensitive?
How can we overcome recursive triggers in SQL?
Can you have more than one trigger on a table?
what are pl/sql collections?
4 Answers JPMorgan Chase, Oracle,
what is the purpose of update command in oracle?
What is the difference between the repeatable read and serializable isolation levels? : Transact sql