Schemas, Foreign Keys, and Entity Relationships
Relational databases use SQL (Structured Query Language) for data definition and manipulation. Data is organized strictly into rows and columns.
CREATE TABLE Customers (
id INTEGER PRIMARY KEY,
name VARCHAR(100),
age INTEGER,
email VARCHAR(100)
);
INSERT INTO Customers (id, name, age, email)
VALUES (123, 'John Doe', 30, 'johndoe@example.com'); SQL excels at joining related entities. For example, an Orders table links to Customers and Products via Foreign Keys.
CREATE TABLE Orders (
order_id INT PRIMARY KEY,
customer_id INT,
product_id INT,
quantity INT,
order_date DATE,
FOREIGN KEY (customer_id) REFERENCES Customers(id),
FOREIGN KEY (product_id) REFERENCES Products(id)
); ──(1:N)──►
◄──(N:1)──