FKs moved to alter caluse

This commit is contained in:
Sergey Kurt 2017-03-19 12:34:19 +03:00
parent e6c6056353
commit 49d052af53

View file

@ -122,10 +122,13 @@ create table cats
( (
id int NOT NULL IDENTITY (1,1) PRIMARY KEY, id int NOT NULL IDENTITY (1,1) PRIMARY KEY,
name varchar(255) not null, name varchar(255) not null,
owner_id int references owner (id) owner_id int
); );
GO GO
ALTER TABLE cats ADD CONSTRAINT cats_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES owner(id);
GO
create table toys create table toys
( (
id int NOT NULL IDENTITY (1,1) PRIMARY KEY, id int NOT NULL IDENTITY (1,1) PRIMARY KEY,
@ -215,38 +218,46 @@ create table elephants
( (
id binary primary key, id binary primary key,
name binary not null, name binary not null,
tiger_id binary NOT NULL unique, tiger_id binary NOT NULL unique
foreign key (tiger_id) references tigers (id)
); );
GO GO
ALTER TABLE elephants ADD CONSTRAINT elephants_tiger_id_fkey FOREIGN KEY (tiger_id) REFERENCES tigers(id);
GO
create table wolves create table wolves
( (
id binary primary key, id binary primary key,
name binary not null, name binary not null,
tiger_id binary not null unique, tiger_id binary not null unique
foreign key (tiger_id) references tigers (id)
); );
GO GO
ALTER TABLE wolves ADD CONSTRAINT wolves_tiger_id_fkey FOREIGN KEY (tiger_id) REFERENCES tigers(id);
GO
create table ants create table ants
( (
id binary primary key, id binary primary key,
name binary not null, name binary not null,
tiger_id binary not null, tiger_id binary not null
foreign key (tiger_id) references tigers (id)
); );
GO GO
ALTER TABLE ants ADD CONSTRAINT ants_tiger_id_fkey FOREIGN KEY (tiger_id) REFERENCES tigers(id);
GO
create table worms create table worms
( (
id binary primary key, id binary primary key,
name binary not null, name binary not null,
tiger_id binary NOT NULL, tiger_id binary NOT NULL
foreign key (tiger_id) references tigers (id)
); );
GO GO
ALTER TABLE worms ADD CONSTRAINT worms_tiger_id_fkey FOREIGN KEY (tiger_id) REFERENCES tigers(id);
GO
create table byte_pilots create table byte_pilots
( (
id binary primary key not null, id binary primary key not null,
@ -273,24 +284,30 @@ create table byte_jets
id binary primary key not null, id binary primary key not null,
name varchar(255), name varchar(255),
byte_pilot_id binary unique NOT NULL, byte_pilot_id binary unique NOT NULL,
byte_airport_id binary NOT NULL, byte_airport_id binary NOT NULL
foreign key (byte_pilot_id) references byte_pilots (id),
foreign key (byte_airport_id) references byte_airports (id)
); );
GO GO
ALTER TABLE byte_jets ADD CONSTRAINT byte_pilot_id_fkey FOREIGN KEY (byte_pilot_id) REFERENCES byte_pilots(id);
GO
ALTER TABLE byte_jets ADD CONSTRAINT byte_airport_id_fkey FOREIGN KEY (byte_airport_id) REFERENCES byte_airports(id);
GO
create table byte_pilot_languages create table byte_pilot_languages
( (
byte_pilot_id binary not null, byte_pilot_id binary not null,
byte_language_id binary not null, byte_language_id binary not null
primary key (byte_pilot_id, byte_language_id),
foreign key (byte_pilot_id) references byte_pilots (id),
foreign key (byte_language_id) references byte_languages (id)
); );
GO GO
ALTER TABLE byte_pilot_languages ADD CONSTRAINT byte_pilot_languages_pkey PRIMARY KEY (byte_pilot_id,byte_language_id);
GO
ALTER TABLE byte_pilot_languages ADD CONSTRAINT byte_pilot_id_fkey FOREIGN KEY (byte_pilot_id) REFERENCES byte_pilots(id);
GO
ALTER TABLE byte_pilot_languages ADD CONSTRAINT byte_language_id_fkey FOREIGN KEY (byte_language_id) REFERENCES byte_languages(id);
GO
create table cars create table cars
( (
id integer not null, id integer not null,
@ -304,22 +321,27 @@ create table car_cars
car_id integer not null, car_id integer not null,
awesome_car_id integer not null, awesome_car_id integer not null,
relation VARCHAR(MAX) not null, relation VARCHAR(MAX) not null,
primary key (car_id, awesome_car_id), primary key (car_id, awesome_car_id)
foreign key (car_id) references cars(id),
foreign key (awesome_car_id) references cars(id)
); );
GO GO
ALTER TABLE car_cars ADD CONSTRAINT car_id_fkey FOREIGN KEY (car_id) REFERENCES cars(id);
GO
ALTER TABLE car_cars ADD CONSTRAINT awesome_car_id_fkey FOREIGN KEY (awesome_car_id) REFERENCES cars(id);
GO
create table trucks create table trucks
( (
id integer not null, id integer not null,
parent_id integer, parent_id integer,
name VARCHAR(MAX), name VARCHAR(MAX),
primary key (id), primary key (id)
foreign key (parent_id) references trucks(id)
); );
GO GO
ALTER TABLE trucks ADD CONSTRAINT parent_id_fkey FOREIGN KEY (parent_id) REFERENCES trucks(id);
GO
CREATE TABLE race CREATE TABLE race
( (
id integer PRIMARY KEY NOT NULL, id integer PRIMARY KEY NOT NULL,
@ -332,20 +354,24 @@ CREATE TABLE race_results
( (
id integer PRIMARY KEY NOT NULL, id integer PRIMARY KEY NOT NULL,
race_id integer, race_id integer,
name VARCHAR(MAX), name VARCHAR(MAX)
foreign key (race_id) references race(id)
); );
GO GO
ALTER TABLE race_results ADD CONSTRAINT race_id_fkey FOREIGN KEY (race_id) REFERENCES race(id);
GO
CREATE TABLE race_result_scratchings CREATE TABLE race_result_scratchings
( (
id integer PRIMARY KEY NOT NULL, id integer PRIMARY KEY NOT NULL,
results_id integer NOT NULL, results_id integer NOT NULL,
name VARCHAR(MAX) NOT NULL, name VARCHAR(MAX) NOT NULL
foreign key (results_id) references race_results(id)
); );
GO GO
ALTER TABLE race_result_scratchings ADD CONSTRAINT results_id_fkey FOREIGN KEY (results_id) REFERENCES race_results(id);
GO
CREATE TABLE pilots CREATE TABLE pilots
( (
id integer NOT NULL, id integer NOT NULL,