diff --git a/lesson2.sql b/lesson2.sql index 70fc88a..0aa7c99 100644 --- a/lesson2.sql +++ b/lesson2.sql @@ -1,55 +1,66 @@ -CREATE TABLE card ( - card_id int [primary key] - card_name text [not null, unique] - card_hp int [not null] - card_set_id int [not null] - card_illustrator_id int [not null] -); - CREATE TABLE illustrator ( - illustrator_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - illustrator_name TEXT NOT NULL + illustrator_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (illustrator_id > 0), + illustrator_name TEXT NOT NULL UNIQUE ); -CREATE TABLE card_set ( - card_set_id int [primary key] - card_set_name text [not null, unique] - card_set_code text [not null, unique] - card_set_release_date date [not null] -); - -CREATE TABLE card_attack ( - card_attack_id int [primary key] - card_id int [not null] - attack_id int [not null] -); - -CREATE TABLE attack ( - attack_id int [primary key] - attack_name text [not null] - attack_base_damage int [not null] -); CREATE TABLE element_type ( - element_type_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + element_type_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (element_type_id > 0), element_type_name TEXT NOT NULL UNIQUE ); -CREATE TABLE attack_energy_cost ( - attack_energy_cost_id int [primary key] - attack_id int [not null] - element_type_id int [not null] - energy_quantity int [not null] +CREATE TABLE card_set ( + set_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (set_id > 0), + set_name TEXT NOT NULL UNIQUE, + set_code TEXT NOT NULL UNIQUE, + set_total_cards INTEGER NOT NULL CHECK (set_total_cards > 0) ); -Ref: "card"."card_illustrator_id" > "illustrator"."illustrator_id" +CREATE TABLE card_pokemon ( + pokemon_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (pokemon_id > 0), + pokemon_name TEXT NOT NULL, + pokemon_hp INTEGER NOT NULL, + pokemon_number INTEGER NOT NULL CHECK (pokemon_number > 0), + pokemon_illustrator_id INTEGER NOT NULL, + pokemon_element_type_id INTEGER NOT NULL, + pokemon_set_id INTEGER NOT NULL, + pokemon_hight_m INTEGER NOT NULL, + pokemon_weight_kg INTEGER NOT NULL, + pokemon_image VARCHAR NOT NULL, + FOREIGN KEY (pokemon_illustrator_id) REFERENCES illustrator(illustrator_id), + FOREIGN KEY (pokemon_element_type_id) REFERENCES element_type(element_type_id), + FOREIGN KEY (pokemon_set_id) REFERENCES card_set(set_id) +); -Ref: "card"."card_set_id" ?> "card_set"."card_set_id" +CREATE TABLE card_trainer ( + trainer_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (trainer_id > 0), + trainer_name TEXT NOT NULL, + trainer_number INTEGER NOT NULL CHECK (card_number > 0), + trainer_illustrator_id INTEGER NOT NULL, + trainer_set_id INTEGER NOT NULL, + trainer_subtype VARCHAR NOT NULL, IN("Item", "Supporter", "Stadium", "Stadium", "Tool"), + trainer_image VARCHAR NOT NULL, + FOREIGN KEY (trainer_illustrator_id) REFERENCES illustrator(illustrator_id), + FOREIGN KEY (trainer_set_id) REFERENCES card_set(set_id) +); -Ref: "card_attack"."card_id" > "card"."card_id" +CREATE TABLE card_energy ( + energy_id INTEGER PRIMARY KEY NOT NULL UNIQUE CHECK (energy_id > 0), + energy_name TEXT NOT NULL, + energy_number INTEGER NOT NULL CHECK (energy_number > 0), + energy_illustrator_id INTEGER NOT NULL, + energy_set_id INTEGER NOT NULL, + energy_image VARCHAR NOT NULL, + FOREIGN KEY (energy_illustrator_id) REFERENCES illustrator(illustrator_id), + FOREIGN KEY (energy_set_id) REFERENCES card_set(set_id) +); -Ref: "attack"."attack_id" "element_type"."element_id" \ No newline at end of file +CREATE TABLE attack ( + attack_id INTEGER PRIMARY KEY NOT NULL CHECK (attack_id > 0), + attack_name TEXT NOT NULL, + attack_base_damage INTEGER NOT NULL CHECK (attack_base_damage >= 0), + attack_damage_modifier TEXT CHECK (attack_damage_modifier IN ('+', 'x')), + attack_card_id INTEGER NOT NULL, + FOREIGN KEY (attack_pokemon_id) REFERENCES card_pokemon(pokemon_id), + FOREIGN KEY (attack_modifier_trainer_id) REFERENCES card_trainer(trainer_id) +);