Person Company City

From NovaOrdis Knowledge Base
Revision as of 23:14, 24 May 2024 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

Internal

Overview

CREATE TABLE person (id integer, name text, company_id integer);
ALTER TABLE person ADD PRIMARY KEY (id);
CREATE TABLE company(id integer, name text, city_id integer);
ALTER TABLE company ADD PRIMARY KEY (id);
ALTER TABLE person ADD FOREIGN KEY (company_id) REFERENCES company(id);
CREATE TABLE city(id integer, name text);
ALTER TABLE city ADD PRIMARY KEY (id);
ALTER TABLE company ADD FOREIGN KEY (city_id) REFERENCES city(id);
INSERT INTO city (id, name) VALUES (100, 'San Francisco');
INSERT INTO city (id, name) VALUES (200, 'New York');
INSERT INTO city (id, name) VALUES (300, 'Chicago');
INSERT INTO company (id, name, city_id) VALUES (10, 'Moonphone', 100);
INSERT INTO company (id, name, city_id) VALUES (20, Vortextime, 200);
INSERT INTO company (id, name, city_id) VALUES (30, 'Bluestone', 300);
INSERT INTO person (id, name, company_id) VALUES (1, 'Alice', 10);
INSERT INTO person (id, name, company_id) VALUES (2, 'Bob', 20);
INSERT INTO person (id, name, company_id) VALUES (3, 'Charlie', 30);