Tables in this data model
- restaurants — 4 columns
- menu_items — 5 columns
- customers — 3 columns
- addresses — 5 columns
- couriers — 3 columns
- orders — 7 columns
- order_items — 4 columns
- delivery_events — 4 columns
- ratings — 4 columns
How to use this ER diagram template
- Click Open in the editor. The ER diagram opens on a new page in FlowDiagram — nothing is uploaded and there is no sign-up.
- Rename, add or delete shapes and drag them where you want; connectors stay attached as things move.
- Drop in vendor logos from the library — 1,160 of them, including every AWS, Azure and Google Cloud service icon — or restyle it with the colour and theme controls.
- Prefer text? Edit the SQL DDL below and paste it in through ☰ → Import / export SQL; the finished model exports back to DDL.
- Export to PNG, SVG or PDF, or press Ctrl+L for a link that carries the whole diagram.
SQL DDL source
The whole template is the text below. Paste it into FlowDiagram, keep it in Git next to the code it describes, or hand it to an AI assistant to extend.
CREATE TABLE restaurants (
restaurant_id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(150) NOT NULL,
cuisine VARCHAR(60),
is_open BOOLEAN NOT NULL
);
CREATE TABLE menu_items (
item_id INTEGER NOT NULL PRIMARY KEY,
restaurant_id INTEGER NOT NULL REFERENCES restaurants(restaurant_id),
name VARCHAR(150) NOT NULL,
price DECIMAL(8,2) NOT NULL,
available BOOLEAN NOT NULL
);
CREATE TABLE customers (
customer_id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(150) NOT NULL,
phone VARCHAR(30)
);
CREATE TABLE addresses (
address_id INTEGER NOT NULL PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(customer_id),
line1 VARCHAR(200) NOT NULL,
lat DECIMAL(9,6),
lng DECIMAL(9,6)
);
CREATE TABLE couriers (
courier_id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(150) NOT NULL,
vehicle VARCHAR(20)
);
CREATE TABLE orders (
order_id INTEGER NOT NULL PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(customer_id),
restaurant_id INTEGER NOT NULL REFERENCES restaurants(restaurant_id),
address_id INTEGER NOT NULL REFERENCES addresses(address_id),
courier_id INTEGER REFERENCES couriers(courier_id),
status VARCHAR(20) NOT NULL,
total DECIMAL(10,2) NOT NULL
);
CREATE TABLE order_items (
order_item_id INTEGER NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL REFERENCES orders(order_id),
item_id INTEGER NOT NULL REFERENCES menu_items(item_id),
quantity INTEGER NOT NULL
);
CREATE TABLE delivery_events (
event_id INTEGER NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL REFERENCES orders(order_id),
status VARCHAR(30) NOT NULL,
occurred_at TIMESTAMP NOT NULL
);
CREATE TABLE ratings (
rating_id INTEGER NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL REFERENCES orders(order_id),
food_stars INTEGER,
courier_stars INTEGER
);
Related: Database schema diagram tool · ER diagram from SQL · All database & er models templates · All 521 templates