- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between Primary key and Foreign key in SQL Database
In the relationaltonal database key is the most important element to maintain the relationship between two tables or to uniquely identify data from the table. Primary key is used to identify data uniquely therefore two rows can’t have the same primary key. It can’t be null.
On the other hand, foreign key is used to maintain relationship between two tables. Primary of a table act as forgein key in the other table. Foreign key in a table enforce Referential Integrity constraint. It can be more than one in the table.
|Sr. No.||Key||Primary Key||Foreign Key|
It is used to uniquely identify data in the table
It is used to maintain relationship between tables
It can’t be null
It can accept the null values
Two or more rows can’t have same primary key
It can carry duplicate value for a foreign key attribute
Primary has clustered index
By default, It is not clustered index
Primary key constraint can be defined on temporary tables
It can’t be defined on temporary tables
- Difference between Primary key and Foreign key in Database
- Difference Between Primary key and Foreign key in DBMS
- Difference between Primary Key and Candidate key
- Difference between Primary Key and Unique key
- How to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle?
- Difference Between Primary and Candidate Key
- What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?
- Primary key Vs Unique key
- How to refer primary key as Foreign to various table in MySQL?
- Foreign Key in RDBMS
- Difference between Private Key and Public Key
- Difference between Super Key and Candidate key
- How to identify composite primary key in any MySQL database table?
- Remove Primary Key in MySQL?
- Reset Primary Key in MySQL