Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE models(
- model_id INT NOT NULL UNIQUE,
- name VARCHAR(50),
- manufacturer_id INT NOT NULL
- );
- CREATE TABLE manufacturers(
- manufacturer_id INT NOT NULL UNIQUE,
- name VARCHAR(50),
- established_on VARCHAR(50)
- );
- INSERT INTO manufacturers VALUES
- (1, 'BMW', '01/03/1916'),
- (2, 'Tesla', '01/01/2003'),
- (3, 'Lada', '01/05/1966');
- INSERT INTO models VALUES
- (101, 'X1', 1),
- (102, 'i6', 1),
- (103, 'Model S', 2),
- (104, 'Model X', 2),
- (105, 'Model 3', 2),
- (106, 'Nova', 3);
- ALTER TABLE models
- ADD CONSTRAINT pk_model_id PRIMARY KEY(model_id);
- ALTER TABLE manufacturers
- ADD CONSTRAINT pk_manufacturer_id PRIMARY KEY(manufacturer_id);
- ALTER TABLE models
- ADD CONSTRAINT fk_monufacturer_model_id FOREIGN KEY(manufacturer_id) REFERENCES manufacturers(manufacturer_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement