Database Management
MySQL
Subjective
Oct 01, 2025
What is a Primary Key and Foreign Key in MySQL?
Detailed Explanation
Primary Key: Uniquely identifies each record in a table, cannot be NULL
Foreign Key: Links two tables together, references primary key of another table
Example:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100)
);
CREATE TABLE orders (
id INT PRIMARY KEY,
user_id INT,
FOREIGN KEY (user_id) REFERENCES users(id)
);
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts