- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 Database
102 Lectures 7.5 hours
152 Lectures 16 hours
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|
|1||Basic||It is used to uniquely identify data in the table||It is used to maintain relationship between tables|
|2||Null||It can’t be null||It can accept the null values|
|3||Duplicate||Two or more rows can’t have same primary key||It can carry duplicate value for a foreign key attribute|
|4||Index||Primary has clustered index||By default, It is not clustered index|
|5||Tables||Primary key constraint can be defined on temporary table||It can’t be defined on temporary tables|
- Difference between Primary key and Foreign key in SQL Database
- Difference Between Primary key and Foreign key in DBMS
- Difference between Primary Key and Candidate key
- Difference between Primary Key and Unique key
- Difference Between Primary and Candidate Key
- How to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle?
- Primary key Vs Unique key
- Difference between Super Key and Candidate key
- Difference between Private Key and Public Key
- What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?
- Foreign Key in RDBMS
- How to refer primary key as Foreign to various table in MySQL?
- Remove Primary Key in MySQL?
- Reset Primary Key in MySQL
- How to identify composite primary key in any MySQL database table?