CREATE TABLE users(
	id INT AUTO_INCREMENT PRIMARY KEY,
	email VARCHAR(64) NOT NULL UNIQUE,
	password CHAR(32) NOT NULL,
	admin BOOL NOT NULL DEFAULT FALSE
) ENGINE=InnoDB;
INSERT INTO users
	SET email = "admin@soccer", password = MD5("admin"), admin = TRUE;
	
CREATE TABLE teams(
	id INT AUTO_INCREMENT PRIMARY KEY,
	user_id INT NOT NULL UNIQUE,
	name VARCHAR(64) CHARACTER SET utf8 NOT NULL UNIQUE,
	country VARCHAR(56) NOT NULL,
	budget INT UNSIGNED NOT NULL,
	CONSTRAINT team_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB;

CREATE TABLE players(
	id INT AUTO_INCREMENT PRIMARY KEY,
	team_id INT,
	first_name VARCHAR(32) CHARACTER SET utf8 NOT NULL,
	last_name VARCHAR(32) CHARACTER SET utf8 NOT NULL,
	country VARCHAR(56) NOT NULL,
	age TINYINT UNSIGNED NOT NULL,
	type ENUM('Goalkeeper', 'Defender', 'Midfielder', 'Attacker') NOT NULL,
	value INT UNSIGNED NOT NULL,
	CONSTRAINT player_team FOREIGN KEY(team_id) REFERENCES teams(id) ON DELETE CASCADE
) ENGINE=InnoDB;

CREATE TABLE market(
	player_id INT PRIMARY KEY,
	price INT UNSIGNED NOT NULL,
	CONSTRAINT market_player FOREIGN KEY(player_id) REFERENCES players(id) ON DELETE CASCADE
) ENGINE=InnoDB;
