A Relational Database Management System (RDBMS) stores data in structured two-dimensional tables made of rows and columns. Tables connect to each other through shared keys so you never duplicate customer details across every order.
In a flat spreadsheet, repeating a customer's email on fifty order rows wastes space and causes update errors. A relational schema splits customers and orders into separate tables linked by an integer identifier.
erDiagram
DEMO_CUSTOMERS ||--o{ DEMO_ORDERS : places
DEMO_CUSTOMERS {
int id PK
string full_name
string email
}
DEMO_ORDERS {
int id PK
int customer_id FK
decimal total_amount
}
demo_customers or demo_orders.email or total_amount.The example below creates a parent demo_departments table and a child demo_employees table connected by a foreign key.
CREATE TABLE demo_departments (
id INT AUTO_INCREMENT PRIMARY KEY,
department_name VARCHAR(100) NOT NULL
);
CREATE TABLE demo_employees (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
department_id INT NOT NULL,
FOREIGN KEY (department_id) REFERENCES demo_departments(id)
);
id primary key to every table so joins and updates target exact rows.An RDBMS like MySQL is the database server software, while SQL is the query language you send to manage data inside it.
Yes, a join table or order line-item table often holds multiple foreign keys pointing to different parent tables.
By default, MySQL blocks the deletion with a foreign key constraint error unless you configure ON DELETE CASCADE or SET NULL.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.