
CREATE TABLE actor (
	actor_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (actor_id)
)


CREATE TABLE address (
	address_id INTEGER NOT NULL, 
	address VARCHAR(50) NOT NULL, 
	address2 VARCHAR(50) DEFAULT NULL, 
	district VARCHAR(20) NOT NULL, 
	city_id INTEGER NOT NULL, 
	postal_code VARCHAR(10) DEFAULT NULL, 
	phone VARCHAR(20) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (address_id), 
	FOREIGN KEY(city_id) REFERENCES city (city_id)
)


CREATE TABLE category (
	category_id INTEGER NOT NULL, 
	name VARCHAR(25) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (category_id)
)


CREATE TABLE city (
	city_id INTEGER NOT NULL, 
	city VARCHAR(50) NOT NULL, 
	country_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (city_id), 
	FOREIGN KEY(country_id) REFERENCES country (country_id)
)


CREATE TABLE country (
	country_id INTEGER NOT NULL, 
	country VARCHAR(50) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (country_id)
)


CREATE TABLE customer (
	customer_id INTEGER NOT NULL, 
	store_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	email VARCHAR(50) DEFAULT NULL, 
	address_id INTEGER NOT NULL, 
	active BOOLEAN DEFAULT TRUE NOT NULL, 
	create_date DATETIME NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
	PRIMARY KEY (customer_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id), 
	FOREIGN KEY(store_id) REFERENCES store (store_id)
)


CREATE TABLE film (
	film_id INTEGER NOT NULL, 
	title VARCHAR(255) NOT NULL, 
	description TEXT DEFAULT NULL, 
	release_year NUMERIC DEFAULT NULL, 
	language_id INTEGER NOT NULL, 
	original_language_id INTEGER DEFAULT NULL, 
	rental_duration INTEGER DEFAULT 3 NOT NULL, 
	rental_rate DECIMAL(4, 2) DEFAULT 4.99 NOT NULL, 
	length INTEGER DEFAULT NULL, 
	replacement_cost DECIMAL(5, 2) DEFAULT 19.99 NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (film_id), 
	FOREIGN KEY(language_id) REFERENCES language (language_id), 
	FOREIGN KEY(original_language_id) REFERENCES language (language_id)
)


CREATE TABLE film_actor (
	actor_id INTEGER NOT NULL, 
	film_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (actor_id, film_id), 
	FOREIGN KEY(actor_id) REFERENCES actor (actor_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id)
)


CREATE TABLE film_category (
	film_id INTEGER NOT NULL, 
	category_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (film_id, category_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id), 
	FOREIGN KEY(category_id) REFERENCES category (category_id)
)


CREATE TABLE film_text (
	film_id SMALLINT NOT NULL, 
	title VARCHAR(255) NOT NULL, 
	description TEXT, 
	PRIMARY KEY (film_id)
)


CREATE TABLE inventory (
	inventory_id INTEGER NOT NULL, 
	film_id INTEGER NOT NULL, 
	store_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (inventory_id), 
	FOREIGN KEY(store_id) REFERENCES store (store_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id)
)


CREATE TABLE language (
	language_id INTEGER NOT NULL, 
	name CHAR(20) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (language_id)
)


CREATE TABLE payment (
	payment_id INTEGER NOT NULL, 
	customer_id INTEGER NOT NULL, 
	staff_id INTEGER NOT NULL, 
	rental_id INTEGER DEFAULT NULL, 
	amount DECIMAL(5, 2) NOT NULL, 
	payment_date DATETIME NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
	PRIMARY KEY (payment_id), 
	FOREIGN KEY(rental_id) REFERENCES rental (rental_id), 
	FOREIGN KEY(customer_id) REFERENCES customer (customer_id), 
	FOREIGN KEY(staff_id) REFERENCES staff (staff_id)
)


CREATE TABLE rental (
	rental_id INTEGER NOT NULL, 
	rental_date DATETIME NOT NULL, 
	inventory_id INTEGER NOT NULL, 
	customer_id INTEGER NOT NULL, 
	return_date DATETIME DEFAULT NULL, 
	staff_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (rental_id), 
	FOREIGN KEY(staff_id) REFERENCES staff (staff_id), 
	FOREIGN KEY(inventory_id) REFERENCES inventory (inventory_id), 
	FOREIGN KEY(customer_id) REFERENCES customer (customer_id)
)


CREATE TABLE staff (
	staff_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	address_id INTEGER NOT NULL, 
	picture BLOB DEFAULT NULL, 
	email VARCHAR(50) DEFAULT NULL, 
	store_id INTEGER NOT NULL, 
	active BOOLEAN DEFAULT TRUE NOT NULL, 
	username VARCHAR(16) NOT NULL, 
	password VARCHAR(40) DEFAULT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (staff_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id)
)


CREATE TABLE store (
	store_id INTEGER NOT NULL, 
	manager_staff_id INTEGER NOT NULL, 
	address_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (store_id), 
	FOREIGN KEY(manager_staff_id) REFERENCES staff (staff_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id)
)

CREATE TABLE actor (
	actor_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (actor_id)
)

/*
2 rows from actor table:
actor_id	first_name	last_name	last_update
1	PENELOPE	GUINESS	2006-02-15 04:34:33
2	NICK	WAHLBERG	2006-02-15 04:34:33
*/


CREATE TABLE address (
	address_id INTEGER NOT NULL, 
	address VARCHAR(50) NOT NULL, 
	address2 VARCHAR(50) DEFAULT NULL, 
	district VARCHAR(20) NOT NULL, 
	city_id INTEGER NOT NULL, 
	postal_code VARCHAR(10) DEFAULT NULL, 
	phone VARCHAR(20) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (address_id), 
	FOREIGN KEY(city_id) REFERENCES city (city_id)
)

/*
2 rows from address table:
address_id	address	address2	district	city_id	postal_code	phone	last_update
1	47 MySakila Drive	None	Alberta	300			2006-02-15 04:45:30
2	28 MySQL Boulevard	None	QLD	576			2006-02-15 04:45:30
*/


CREATE TABLE category (
	category_id INTEGER NOT NULL, 
	name VARCHAR(25) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (category_id)
)

/*
2 rows from category table:
category_id	name	last_update
1	Action	2006-02-15 04:46:27
2	Animation	2006-02-15 04:46:27
*/


CREATE TABLE city (
	city_id INTEGER NOT NULL, 
	city VARCHAR(50) NOT NULL, 
	country_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (city_id), 
	FOREIGN KEY(country_id) REFERENCES country (country_id)
)

/*
2 rows from city table:
city_id	city	country_id	last_update
1	A Corua (La Corua)	87	2006-02-15 04:45:25
2	Abha	82	2006-02-15 04:45:25
*/


CREATE TABLE country (
	country_id INTEGER NOT NULL, 
	country VARCHAR(50) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (country_id)
)

/*
2 rows from country table:
country_id	country	last_update
1	Afghanistan	2006-02-15 04:44:00
2	Algeria	2006-02-15 04:44:00
*/


CREATE TABLE customer (
	customer_id INTEGER NOT NULL, 
	store_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	email VARCHAR(50) DEFAULT NULL, 
	address_id INTEGER NOT NULL, 
	active BOOLEAN DEFAULT TRUE NOT NULL, 
	create_date DATETIME NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
	PRIMARY KEY (customer_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id), 
	FOREIGN KEY(store_id) REFERENCES store (store_id)
)

/*
2 rows from customer table:
customer_id	store_id	first_name	last_name	email	address_id	active	create_date	last_update
1	1	MARY	SMITH	MARY.SMITH@sakilacustomer.org	5	True	2006-02-14 22:04:36	2006-02-15 04:57:20
2	1	PATRICIA	JOHNSON	PATRICIA.JOHNSON@sakilacustomer.org	6	True	2006-02-14 22:04:36	2006-02-15 04:57:20
*/


CREATE TABLE film (
	film_id INTEGER NOT NULL, 
	title VARCHAR(255) NOT NULL, 
	description TEXT DEFAULT NULL, 
	release_year NUMERIC DEFAULT NULL, 
	language_id INTEGER NOT NULL, 
	original_language_id INTEGER DEFAULT NULL, 
	rental_duration INTEGER DEFAULT 3 NOT NULL, 
	rental_rate DECIMAL(4, 2) DEFAULT 4.99 NOT NULL, 
	length INTEGER DEFAULT NULL, 
	replacement_cost DECIMAL(5, 2) DEFAULT 19.99 NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (film_id), 
	FOREIGN KEY(language_id) REFERENCES language (language_id), 
	FOREIGN KEY(original_language_id) REFERENCES language (language_id)
)

/*
2 rows from film table:
film_id	title	description	release_year	language_id	original_language_id	rental_duration	rental_rate	length	replacement_cost	last_update
1	ACADEMY DINOSAUR	A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies	2006.0000000000	1	None	6	0.99	86	20.99	2006-02-15 05:03:42
2	ACE GOLDFINGER	A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China	2006.0000000000	1	None	3	4.99	48	12.99	2006-02-15 05:03:42
*/


CREATE TABLE film_actor (
	actor_id INTEGER NOT NULL, 
	film_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (actor_id, film_id), 
	FOREIGN KEY(actor_id) REFERENCES actor (actor_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id)
)

/*
2 rows from film_actor table:
actor_id	film_id	last_update
1	1	2006-02-15 05:05:03
1	23	2006-02-15 05:05:03
*/


CREATE TABLE film_category (
	film_id INTEGER NOT NULL, 
	category_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (film_id, category_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id), 
	FOREIGN KEY(category_id) REFERENCES category (category_id)
)

/*
2 rows from film_category table:
film_id	category_id	last_update
1	6	2006-02-15 05:07:09
2	11	2006-02-15 05:07:09
*/


CREATE TABLE film_text (
	film_id SMALLINT NOT NULL, 
	title VARCHAR(255) NOT NULL, 
	description TEXT, 
	PRIMARY KEY (film_id)
)

/*
2 rows from film_text table:
film_id	title	description

*/


CREATE TABLE inventory (
	inventory_id INTEGER NOT NULL, 
	film_id INTEGER NOT NULL, 
	store_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (inventory_id), 
	FOREIGN KEY(store_id) REFERENCES store (store_id), 
	FOREIGN KEY(film_id) REFERENCES film (film_id)
)

/*
2 rows from inventory table:
inventory_id	film_id	store_id	last_update
1	1	1	2006-02-15 05:09:17
2	1	1	2006-02-15 05:09:17
*/


CREATE TABLE language (
	language_id INTEGER NOT NULL, 
	name CHAR(20) NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (language_id)
)

/*
2 rows from language table:
language_id	name	last_update

*/


CREATE TABLE payment (
	payment_id INTEGER NOT NULL, 
	customer_id INTEGER NOT NULL, 
	staff_id INTEGER NOT NULL, 
	rental_id INTEGER DEFAULT NULL, 
	amount DECIMAL(5, 2) NOT NULL, 
	payment_date DATETIME NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
	PRIMARY KEY (payment_id), 
	FOREIGN KEY(rental_id) REFERENCES rental (rental_id), 
	FOREIGN KEY(customer_id) REFERENCES customer (customer_id), 
	FOREIGN KEY(staff_id) REFERENCES staff (staff_id)
)

/*
2 rows from payment table:
payment_id	customer_id	staff_id	rental_id	amount	payment_date	last_update
1	1	1	76	2.99	2005-05-25 11:30:37	2006-02-15 22:12:30
2	1	1	573	0.99	2005-05-28 10:35:23	2006-02-15 22:12:30
*/


CREATE TABLE rental (
	rental_id INTEGER NOT NULL, 
	rental_date DATETIME NOT NULL, 
	inventory_id INTEGER NOT NULL, 
	customer_id INTEGER NOT NULL, 
	return_date DATETIME DEFAULT NULL, 
	staff_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (rental_id), 
	FOREIGN KEY(staff_id) REFERENCES staff (staff_id), 
	FOREIGN KEY(inventory_id) REFERENCES inventory (inventory_id), 
	FOREIGN KEY(customer_id) REFERENCES customer (customer_id)
)

/*
2 rows from rental table:
rental_id	rental_date	inventory_id	customer_id	return_date	staff_id	last_update
1	2005-05-24 22:53:30	367	130	2005-05-26 22:04:30	1	2006-02-15 21:30:53
2	2005-05-24 22:54:33	1525	459	2005-05-28 19:40:33	1	2006-02-15 21:30:53
*/


CREATE TABLE staff (
	staff_id INTEGER NOT NULL, 
	first_name VARCHAR(45) NOT NULL, 
	last_name VARCHAR(45) NOT NULL, 
	address_id INTEGER NOT NULL, 
	picture BLOB DEFAULT NULL, 
	email VARCHAR(50) DEFAULT NULL, 
	store_id INTEGER NOT NULL, 
	active BOOLEAN DEFAULT TRUE NOT NULL, 
	username VARCHAR(16) NOT NULL, 
	password VARCHAR(40) DEFAULT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (staff_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id)
)

/*
2 rows from staff table:
staff_id	first_name	last_name	address_id	picture	email	store_id	active	username	password	last_update

*/


CREATE TABLE store (
	store_id INTEGER NOT NULL, 
	manager_staff_id INTEGER NOT NULL, 
	address_id INTEGER NOT NULL, 
	last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, 
	PRIMARY KEY (store_id), 
	FOREIGN KEY(manager_staff_id) REFERENCES staff (staff_id), 
	FOREIGN KEY(address_id) REFERENCES address (address_id)
)

/*
2 rows from store table:
store_id	manager_staff_id	address_id	last_update

*/
How many stores are there?
SELECT count(*) FROM store
[{'count(*)': 0}]