initial commit
This commit is contained in:
commit
a07a5a15de
16 changed files with 49840 additions and 0 deletions
BIN
AltGeldMart/AltgeldMart.pdf
Normal file
BIN
AltGeldMart/AltgeldMart.pdf
Normal file
Binary file not shown.
23
AltGeldMart/ReadMe.txt
Normal file
23
AltGeldMart/ReadMe.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Read the description of the AltgeldMart database included in this zip.
|
||||||
|
|
||||||
|
The data values in these inserts might not exactly match the data values shown in the notes. You can run the demos to check the current values in the tables.
|
||||||
|
|
||||||
|
Before running these scripts you need to have created the databases:
|
||||||
|
employee
|
||||||
|
product
|
||||||
|
customer
|
||||||
|
orderEntry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Treat these creates and inserts as scripts and run from the command line- this is easier and less error prone than using copy and paste. You should have no error messages when you run the scripts.
|
||||||
|
|
||||||
|
The order for running the scripts is
|
||||||
|
Check that you have created the databases and have the proper permissions.
|
||||||
|
1. run the create script - it will remove any previous copy of the tables you might have.
|
||||||
|
2. run the inserts script - it will delete any data from the tables and then do the inserts.
|
||||||
|
|
||||||
|
If later in the semester you want to get back to the original set of data and you have not dropped any of the tables, you can just run the inserts script.
|
||||||
|
Scripts: if you are running these as scripts you can send the output to an LST file.
|
||||||
|
|
||||||
|
|
BIN
AltGeldMart/altgeld.sqlt
Executable file
BIN
AltGeldMart/altgeld.sqlt
Executable file
Binary file not shown.
1033
AltGeldMart/altgeld_db_setup.sql
Normal file
1033
AltGeldMart/altgeld_db_setup.sql
Normal file
File diff suppressed because it is too large
Load diff
1013
AltGeldMart/altgeld_db_setup_sqlite.sql
Normal file
1013
AltGeldMart/altgeld_db_setup_sqlite.sql
Normal file
File diff suppressed because it is too large
Load diff
7
README.md
Normal file
7
README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Sample Databases
|
||||||
|
|
||||||
|
These are sample databases for MySQL, PostgreSQL, and SQLite
|
||||||
|
|
||||||
|
AltGeldMart and vets were used heavily in a MySQL programming course
|
||||||
|
|
||||||
|
|
BIN
SQLite/chinook.zip
Normal file
BIN
SQLite/chinook.zip
Normal file
Binary file not shown.
BIN
SQLite/sqlite-sample-database-diagram-color.pdf
Normal file
BIN
SQLite/sqlite-sample-database-diagram-color.pdf
Normal file
Binary file not shown.
BIN
SQLite/sqlite-sample-database-diagram.pdf
Normal file
BIN
SQLite/sqlite-sample-database-diagram.pdf
Normal file
Binary file not shown.
5
Sakila/info.md
Normal file
5
Sakila/info.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Sakila Sample Database
|
||||||
|
|
||||||
|
<https://dev.mysql.com/doc/sakila/en/>
|
||||||
|
|
||||||
|
|
46449
Sakila/sakila-data.sql
Normal file
46449
Sakila/sakila-data.sql
Normal file
File diff suppressed because one or more lines are too long
684
Sakila/sakila-schema.sql
Normal file
684
Sakila/sakila-schema.sql
Normal file
|
@ -0,0 +1,684 @@
|
||||||
|
-- Sakila Sample Database Schema
|
||||||
|
-- Version 1.2
|
||||||
|
|
||||||
|
-- Copyright (c) 2006, 2019, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
-- Redistribution and use in source and binary forms, with or without
|
||||||
|
-- modification, are permitted provided that the following conditions are
|
||||||
|
-- met:
|
||||||
|
|
||||||
|
-- * Redistributions of source code must retain the above copyright notice,
|
||||||
|
-- this list of conditions and the following disclaimer.
|
||||||
|
-- * Redistributions in binary form must reproduce the above copyright
|
||||||
|
-- notice, this list of conditions and the following disclaimer in the
|
||||||
|
-- documentation and/or other materials provided with the distribution.
|
||||||
|
-- * Neither the name of Oracle nor the names of its contributors may be used
|
||||||
|
-- to endorse or promote products derived from this software without
|
||||||
|
-- specific prior written permission.
|
||||||
|
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
|
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
-- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||||
|
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||||
|
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||||
|
|
||||||
|
DROP SCHEMA IF EXISTS sakila;
|
||||||
|
CREATE SCHEMA sakila;
|
||||||
|
USE sakila;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `actor`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE actor (
|
||||||
|
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
first_name VARCHAR(45) NOT NULL,
|
||||||
|
last_name VARCHAR(45) NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (actor_id),
|
||||||
|
KEY idx_actor_last_name (last_name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `address`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE address (
|
||||||
|
address_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
address VARCHAR(50) NOT NULL,
|
||||||
|
address2 VARCHAR(50) DEFAULT NULL,
|
||||||
|
district VARCHAR(20) NOT NULL,
|
||||||
|
city_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
postal_code VARCHAR(10) DEFAULT NULL,
|
||||||
|
phone VARCHAR(20) NOT NULL,
|
||||||
|
-- Add GEOMETRY column for MySQL 5.7.5 and higher
|
||||||
|
-- Also include SRID attribute for MySQL 8.0.3 and higher
|
||||||
|
/*!50705 location GEOMETRY */ /*!80003 SRID 0 */ /*!50705 NOT NULL,*/
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (address_id),
|
||||||
|
KEY idx_fk_city_id (city_id),
|
||||||
|
/*!50705 SPATIAL KEY `idx_location` (location),*/
|
||||||
|
CONSTRAINT `fk_address_city` FOREIGN KEY (city_id) REFERENCES city (city_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `category`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE category (
|
||||||
|
category_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
name VARCHAR(25) NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (category_id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `city`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE city (
|
||||||
|
city_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
city VARCHAR(50) NOT NULL,
|
||||||
|
country_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (city_id),
|
||||||
|
KEY idx_fk_country_id (country_id),
|
||||||
|
CONSTRAINT `fk_city_country` FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `country`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE country (
|
||||||
|
country_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
country VARCHAR(50) NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (country_id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `customer`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE customer (
|
||||||
|
customer_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
store_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
first_name VARCHAR(45) NOT NULL,
|
||||||
|
last_name VARCHAR(45) NOT NULL,
|
||||||
|
email VARCHAR(50) DEFAULT NULL,
|
||||||
|
address_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
create_date DATETIME NOT NULL,
|
||||||
|
last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (customer_id),
|
||||||
|
KEY idx_fk_store_id (store_id),
|
||||||
|
KEY idx_fk_address_id (address_id),
|
||||||
|
KEY idx_last_name (last_name),
|
||||||
|
CONSTRAINT fk_customer_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_customer_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `film`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE film (
|
||||||
|
film_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
title VARCHAR(128) NOT NULL,
|
||||||
|
description TEXT DEFAULT NULL,
|
||||||
|
release_year YEAR DEFAULT NULL,
|
||||||
|
language_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
original_language_id TINYINT UNSIGNED DEFAULT NULL,
|
||||||
|
rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3,
|
||||||
|
rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99,
|
||||||
|
length SMALLINT UNSIGNED DEFAULT NULL,
|
||||||
|
replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99,
|
||||||
|
rating ENUM('G','PG','PG-13','R','NC-17') DEFAULT 'G',
|
||||||
|
special_features SET('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (film_id),
|
||||||
|
KEY idx_title (title),
|
||||||
|
KEY idx_fk_language_id (language_id),
|
||||||
|
KEY idx_fk_original_language_id (original_language_id),
|
||||||
|
CONSTRAINT fk_film_language FOREIGN KEY (language_id) REFERENCES language (language_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES language (language_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `film_actor`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE film_actor (
|
||||||
|
actor_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
film_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (actor_id,film_id),
|
||||||
|
KEY idx_fk_film_id (`film_id`),
|
||||||
|
CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `film_category`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE film_category (
|
||||||
|
film_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
category_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (film_id, category_id),
|
||||||
|
CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `film_text`
|
||||||
|
--
|
||||||
|
-- InnoDB added FULLTEXT support in 5.6.10. If you use an
|
||||||
|
-- earlier version, then consider upgrading (recommended) or
|
||||||
|
-- changing InnoDB to MyISAM as the film_text engine
|
||||||
|
--
|
||||||
|
|
||||||
|
-- Use InnoDB for film_text as of 5.6.10, MyISAM prior to 5.6.10.
|
||||||
|
SET @old_default_storage_engine = @@default_storage_engine;
|
||||||
|
SET @@default_storage_engine = 'MyISAM';
|
||||||
|
/*!50610 SET @@default_storage_engine = 'InnoDB'*/;
|
||||||
|
|
||||||
|
CREATE TABLE film_text (
|
||||||
|
film_id SMALLINT NOT NULL,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
PRIMARY KEY (film_id),
|
||||||
|
FULLTEXT KEY idx_title_description (title,description)
|
||||||
|
) DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @@default_storage_engine = @old_default_storage_engine;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Triggers for loading film_text from film
|
||||||
|
--
|
||||||
|
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE TRIGGER `ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN
|
||||||
|
INSERT INTO film_text (film_id, title, description)
|
||||||
|
VALUES (new.film_id, new.title, new.description);
|
||||||
|
END;;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TRIGGER `upd_film` AFTER UPDATE ON `film` FOR EACH ROW BEGIN
|
||||||
|
IF (old.title != new.title) OR (old.description != new.description) OR (old.film_id != new.film_id)
|
||||||
|
THEN
|
||||||
|
UPDATE film_text
|
||||||
|
SET title=new.title,
|
||||||
|
description=new.description,
|
||||||
|
film_id=new.film_id
|
||||||
|
WHERE film_id=old.film_id;
|
||||||
|
END IF;
|
||||||
|
END;;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TRIGGER `del_film` AFTER DELETE ON `film` FOR EACH ROW BEGIN
|
||||||
|
DELETE FROM film_text WHERE film_id = old.film_id;
|
||||||
|
END;;
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `inventory`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE inventory (
|
||||||
|
inventory_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
film_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
store_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (inventory_id),
|
||||||
|
KEY idx_fk_film_id (film_id),
|
||||||
|
KEY idx_store_id_film_id (store_id,film_id),
|
||||||
|
CONSTRAINT fk_inventory_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_inventory_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `language`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE language (
|
||||||
|
language_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
name CHAR(20) NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (language_id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `payment`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE payment (
|
||||||
|
payment_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
customer_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
staff_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
rental_id INT DEFAULT NULL,
|
||||||
|
amount DECIMAL(5,2) NOT NULL,
|
||||||
|
payment_date DATETIME NOT NULL,
|
||||||
|
last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (payment_id),
|
||||||
|
KEY idx_fk_staff_id (staff_id),
|
||||||
|
KEY idx_fk_customer_id (customer_id),
|
||||||
|
CONSTRAINT fk_payment_rental FOREIGN KEY (rental_id) REFERENCES rental (rental_id) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_payment_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_payment_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `rental`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE rental (
|
||||||
|
rental_id INT NOT NULL AUTO_INCREMENT,
|
||||||
|
rental_date DATETIME NOT NULL,
|
||||||
|
inventory_id MEDIUMINT UNSIGNED NOT NULL,
|
||||||
|
customer_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
return_date DATETIME DEFAULT NULL,
|
||||||
|
staff_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (rental_id),
|
||||||
|
UNIQUE KEY (rental_date,inventory_id,customer_id),
|
||||||
|
KEY idx_fk_inventory_id (inventory_id),
|
||||||
|
KEY idx_fk_customer_id (customer_id),
|
||||||
|
KEY idx_fk_staff_id (staff_id),
|
||||||
|
CONSTRAINT fk_rental_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_rental_inventory FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_rental_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `staff`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE staff (
|
||||||
|
staff_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
first_name VARCHAR(45) NOT NULL,
|
||||||
|
last_name VARCHAR(45) NOT NULL,
|
||||||
|
address_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
picture BLOB DEFAULT NULL,
|
||||||
|
email VARCHAR(50) DEFAULT NULL,
|
||||||
|
store_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
username VARCHAR(16) NOT NULL,
|
||||||
|
password VARCHAR(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (staff_id),
|
||||||
|
KEY idx_fk_store_id (store_id),
|
||||||
|
KEY idx_fk_address_id (address_id),
|
||||||
|
CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `store`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE store (
|
||||||
|
store_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
manager_staff_id TINYINT UNSIGNED NOT NULL,
|
||||||
|
address_id SMALLINT UNSIGNED NOT NULL,
|
||||||
|
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (store_id),
|
||||||
|
UNIQUE KEY idx_unique_manager (manager_staff_id),
|
||||||
|
KEY idx_fk_address_id (address_id),
|
||||||
|
CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT fk_store_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `customer_list`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW customer_list
|
||||||
|
AS
|
||||||
|
SELECT cu.customer_id AS ID, CONCAT(cu.first_name, _utf8mb4' ', cu.last_name) AS name, a.address AS address, a.postal_code AS `zip code`,
|
||||||
|
a.phone AS phone, city.city AS city, country.country AS country, IF(cu.active, _utf8mb4'active',_utf8mb4'') AS notes, cu.store_id AS SID
|
||||||
|
FROM customer AS cu JOIN address AS a ON cu.address_id = a.address_id JOIN city ON a.city_id = city.city_id
|
||||||
|
JOIN country ON city.country_id = country.country_id;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `film_list`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW film_list
|
||||||
|
AS
|
||||||
|
SELECT film.film_id AS FID, film.title AS title, film.description AS description, category.name AS category, film.rental_rate AS price,
|
||||||
|
film.length AS length, film.rating AS rating, GROUP_CONCAT(CONCAT(actor.first_name, _utf8mb4' ', actor.last_name) SEPARATOR ', ') AS actors
|
||||||
|
FROM category LEFT JOIN film_category ON category.category_id = film_category.category_id LEFT JOIN film ON film_category.film_id = film.film_id
|
||||||
|
JOIN film_actor ON film.film_id = film_actor.film_id
|
||||||
|
JOIN actor ON film_actor.actor_id = actor.actor_id
|
||||||
|
GROUP BY film.film_id, category.name;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `nicer_but_slower_film_list`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW nicer_but_slower_film_list
|
||||||
|
AS
|
||||||
|
SELECT film.film_id AS FID, film.title AS title, film.description AS description, category.name AS category, film.rental_rate AS price,
|
||||||
|
film.length AS length, film.rating AS rating, GROUP_CONCAT(CONCAT(CONCAT(UCASE(SUBSTR(actor.first_name,1,1)),
|
||||||
|
LCASE(SUBSTR(actor.first_name,2,LENGTH(actor.first_name))),_utf8mb4' ',CONCAT(UCASE(SUBSTR(actor.last_name,1,1)),
|
||||||
|
LCASE(SUBSTR(actor.last_name,2,LENGTH(actor.last_name)))))) SEPARATOR ', ') AS actors
|
||||||
|
FROM category LEFT JOIN film_category ON category.category_id = film_category.category_id LEFT JOIN film ON film_category.film_id = film.film_id
|
||||||
|
JOIN film_actor ON film.film_id = film_actor.film_id
|
||||||
|
JOIN actor ON film_actor.actor_id = actor.actor_id
|
||||||
|
GROUP BY film.film_id, category.name;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `staff_list`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW staff_list
|
||||||
|
AS
|
||||||
|
SELECT s.staff_id AS ID, CONCAT(s.first_name, _utf8mb4' ', s.last_name) AS name, a.address AS address, a.postal_code AS `zip code`, a.phone AS phone,
|
||||||
|
city.city AS city, country.country AS country, s.store_id AS SID
|
||||||
|
FROM staff AS s JOIN address AS a ON s.address_id = a.address_id JOIN city ON a.city_id = city.city_id
|
||||||
|
JOIN country ON city.country_id = country.country_id;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `sales_by_store`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW sales_by_store
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
CONCAT(c.city, _utf8mb4',', cy.country) AS store
|
||||||
|
, CONCAT(m.first_name, _utf8mb4' ', m.last_name) AS manager
|
||||||
|
, SUM(p.amount) AS total_sales
|
||||||
|
FROM payment AS p
|
||||||
|
INNER JOIN rental AS r ON p.rental_id = r.rental_id
|
||||||
|
INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id
|
||||||
|
INNER JOIN store AS s ON i.store_id = s.store_id
|
||||||
|
INNER JOIN address AS a ON s.address_id = a.address_id
|
||||||
|
INNER JOIN city AS c ON a.city_id = c.city_id
|
||||||
|
INNER JOIN country AS cy ON c.country_id = cy.country_id
|
||||||
|
INNER JOIN staff AS m ON s.manager_staff_id = m.staff_id
|
||||||
|
GROUP BY s.store_id
|
||||||
|
ORDER BY cy.country, c.city;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `sales_by_film_category`
|
||||||
|
--
|
||||||
|
-- Note that total sales will add up to >100% because
|
||||||
|
-- some titles belong to more than 1 category
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE VIEW sales_by_film_category
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
c.name AS category
|
||||||
|
, SUM(p.amount) AS total_sales
|
||||||
|
FROM payment AS p
|
||||||
|
INNER JOIN rental AS r ON p.rental_id = r.rental_id
|
||||||
|
INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id
|
||||||
|
INNER JOIN film AS f ON i.film_id = f.film_id
|
||||||
|
INNER JOIN film_category AS fc ON f.film_id = fc.film_id
|
||||||
|
INNER JOIN category AS c ON fc.category_id = c.category_id
|
||||||
|
GROUP BY c.name
|
||||||
|
ORDER BY total_sales DESC;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- View structure for view `actor_info`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW actor_info
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
a.actor_id,
|
||||||
|
a.first_name,
|
||||||
|
a.last_name,
|
||||||
|
GROUP_CONCAT(DISTINCT CONCAT(c.name, ': ',
|
||||||
|
(SELECT GROUP_CONCAT(f.title ORDER BY f.title SEPARATOR ', ')
|
||||||
|
FROM sakila.film f
|
||||||
|
INNER JOIN sakila.film_category fc
|
||||||
|
ON f.film_id = fc.film_id
|
||||||
|
INNER JOIN sakila.film_actor fa
|
||||||
|
ON f.film_id = fa.film_id
|
||||||
|
WHERE fc.category_id = c.category_id
|
||||||
|
AND fa.actor_id = a.actor_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
ORDER BY c.name SEPARATOR '; ')
|
||||||
|
AS film_info
|
||||||
|
FROM sakila.actor a
|
||||||
|
LEFT JOIN sakila.film_actor fa
|
||||||
|
ON a.actor_id = fa.actor_id
|
||||||
|
LEFT JOIN sakila.film_category fc
|
||||||
|
ON fa.film_id = fc.film_id
|
||||||
|
LEFT JOIN sakila.category c
|
||||||
|
ON fc.category_id = c.category_id
|
||||||
|
GROUP BY a.actor_id, a.first_name, a.last_name;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Procedure structure for procedure `rewards_report`
|
||||||
|
--
|
||||||
|
|
||||||
|
DELIMITER //
|
||||||
|
|
||||||
|
CREATE PROCEDURE rewards_report (
|
||||||
|
IN min_monthly_purchases TINYINT UNSIGNED
|
||||||
|
, IN min_dollar_amount_purchased DECIMAL(10,2)
|
||||||
|
, OUT count_rewardees INT
|
||||||
|
)
|
||||||
|
LANGUAGE SQL
|
||||||
|
NOT DETERMINISTIC
|
||||||
|
READS SQL DATA
|
||||||
|
SQL SECURITY DEFINER
|
||||||
|
COMMENT 'Provides a customizable report on best customers'
|
||||||
|
proc: BEGIN
|
||||||
|
|
||||||
|
DECLARE last_month_start DATE;
|
||||||
|
DECLARE last_month_end DATE;
|
||||||
|
|
||||||
|
/* Some sanity checks... */
|
||||||
|
IF min_monthly_purchases = 0 THEN
|
||||||
|
SELECT 'Minimum monthly purchases parameter must be > 0';
|
||||||
|
LEAVE proc;
|
||||||
|
END IF;
|
||||||
|
IF min_dollar_amount_purchased = 0.00 THEN
|
||||||
|
SELECT 'Minimum monthly dollar amount purchased parameter must be > $0.00';
|
||||||
|
LEAVE proc;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
/* Determine start and end time periods */
|
||||||
|
SET last_month_start = DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH);
|
||||||
|
SET last_month_start = STR_TO_DATE(CONCAT(YEAR(last_month_start),'-',MONTH(last_month_start),'-01'),'%Y-%m-%d');
|
||||||
|
SET last_month_end = LAST_DAY(last_month_start);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create a temporary storage area for
|
||||||
|
Customer IDs.
|
||||||
|
*/
|
||||||
|
CREATE TEMPORARY TABLE tmpCustomer (customer_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Find all customers meeting the
|
||||||
|
monthly purchase requirements
|
||||||
|
*/
|
||||||
|
INSERT INTO tmpCustomer (customer_id)
|
||||||
|
SELECT p.customer_id
|
||||||
|
FROM payment AS p
|
||||||
|
WHERE DATE(p.payment_date) BETWEEN last_month_start AND last_month_end
|
||||||
|
GROUP BY customer_id
|
||||||
|
HAVING SUM(p.amount) > min_dollar_amount_purchased
|
||||||
|
AND COUNT(customer_id) > min_monthly_purchases;
|
||||||
|
|
||||||
|
/* Populate OUT parameter with count of found customers */
|
||||||
|
SELECT COUNT(*) FROM tmpCustomer INTO count_rewardees;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Output ALL customer information of matching rewardees.
|
||||||
|
Customize output as needed.
|
||||||
|
*/
|
||||||
|
SELECT c.*
|
||||||
|
FROM tmpCustomer AS t
|
||||||
|
INNER JOIN customer AS c ON t.customer_id = c.customer_id;
|
||||||
|
|
||||||
|
/* Clean up */
|
||||||
|
DROP TABLE tmpCustomer;
|
||||||
|
END //
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE FUNCTION get_customer_balance(p_customer_id INT, p_effective_date DATETIME) RETURNS DECIMAL(5,2)
|
||||||
|
DETERMINISTIC
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
#OK, WE NEED TO CALCULATE THE CURRENT BALANCE GIVEN A CUSTOMER_ID AND A DATE
|
||||||
|
#THAT WE WANT THE BALANCE TO BE EFFECTIVE FOR. THE BALANCE IS:
|
||||||
|
# 1) RENTAL FEES FOR ALL PREVIOUS RENTALS
|
||||||
|
# 2) ONE DOLLAR FOR EVERY DAY THE PREVIOUS RENTALS ARE OVERDUE
|
||||||
|
# 3) IF A FILM IS MORE THAN RENTAL_DURATION * 2 OVERDUE, CHARGE THE REPLACEMENT_COST
|
||||||
|
# 4) SUBTRACT ALL PAYMENTS MADE BEFORE THE DATE SPECIFIED
|
||||||
|
|
||||||
|
DECLARE v_rentfees DECIMAL(5,2); #FEES PAID TO RENT THE VIDEOS INITIALLY
|
||||||
|
DECLARE v_overfees INTEGER; #LATE FEES FOR PRIOR RENTALS
|
||||||
|
DECLARE v_payments DECIMAL(5,2); #SUM OF PAYMENTS MADE PREVIOUSLY
|
||||||
|
|
||||||
|
SELECT IFNULL(SUM(film.rental_rate),0) INTO v_rentfees
|
||||||
|
FROM film, inventory, rental
|
||||||
|
WHERE film.film_id = inventory.film_id
|
||||||
|
AND inventory.inventory_id = rental.inventory_id
|
||||||
|
AND rental.rental_date <= p_effective_date
|
||||||
|
AND rental.customer_id = p_customer_id;
|
||||||
|
|
||||||
|
SELECT IFNULL(SUM(IF((TO_DAYS(rental.return_date) - TO_DAYS(rental.rental_date)) > film.rental_duration,
|
||||||
|
((TO_DAYS(rental.return_date) - TO_DAYS(rental.rental_date)) - film.rental_duration),0)),0) INTO v_overfees
|
||||||
|
FROM rental, inventory, film
|
||||||
|
WHERE film.film_id = inventory.film_id
|
||||||
|
AND inventory.inventory_id = rental.inventory_id
|
||||||
|
AND rental.rental_date <= p_effective_date
|
||||||
|
AND rental.customer_id = p_customer_id;
|
||||||
|
|
||||||
|
|
||||||
|
SELECT IFNULL(SUM(payment.amount),0) INTO v_payments
|
||||||
|
FROM payment
|
||||||
|
|
||||||
|
WHERE payment.payment_date <= p_effective_date
|
||||||
|
AND payment.customer_id = p_customer_id;
|
||||||
|
|
||||||
|
RETURN v_rentfees + v_overfees - v_payments;
|
||||||
|
END $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE PROCEDURE film_in_stock(IN p_film_id INT, IN p_store_id INT, OUT p_film_count INT)
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
SELECT inventory_id
|
||||||
|
FROM inventory
|
||||||
|
WHERE film_id = p_film_id
|
||||||
|
AND store_id = p_store_id
|
||||||
|
AND inventory_in_stock(inventory_id);
|
||||||
|
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM inventory
|
||||||
|
WHERE film_id = p_film_id
|
||||||
|
AND store_id = p_store_id
|
||||||
|
AND inventory_in_stock(inventory_id)
|
||||||
|
INTO p_film_count;
|
||||||
|
END $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE PROCEDURE film_not_in_stock(IN p_film_id INT, IN p_store_id INT, OUT p_film_count INT)
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
SELECT inventory_id
|
||||||
|
FROM inventory
|
||||||
|
WHERE film_id = p_film_id
|
||||||
|
AND store_id = p_store_id
|
||||||
|
AND NOT inventory_in_stock(inventory_id);
|
||||||
|
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM inventory
|
||||||
|
WHERE film_id = p_film_id
|
||||||
|
AND store_id = p_store_id
|
||||||
|
AND NOT inventory_in_stock(inventory_id)
|
||||||
|
INTO p_film_count;
|
||||||
|
END $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE FUNCTION inventory_held_by_customer(p_inventory_id INT) RETURNS INT
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
DECLARE v_customer_id INT;
|
||||||
|
DECLARE EXIT HANDLER FOR NOT FOUND RETURN NULL;
|
||||||
|
|
||||||
|
SELECT customer_id INTO v_customer_id
|
||||||
|
FROM rental
|
||||||
|
WHERE return_date IS NULL
|
||||||
|
AND inventory_id = p_inventory_id;
|
||||||
|
|
||||||
|
RETURN v_customer_id;
|
||||||
|
END $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE FUNCTION inventory_in_stock(p_inventory_id INT) RETURNS BOOLEAN
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
DECLARE v_rentals INT;
|
||||||
|
DECLARE v_out INT;
|
||||||
|
|
||||||
|
#AN ITEM IS IN-STOCK IF THERE ARE EITHER NO ROWS IN THE rental TABLE
|
||||||
|
#FOR THE ITEM OR ALL ROWS HAVE return_date POPULATED
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO v_rentals
|
||||||
|
FROM rental
|
||||||
|
WHERE inventory_id = p_inventory_id;
|
||||||
|
|
||||||
|
IF v_rentals = 0 THEN
|
||||||
|
RETURN TRUE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT COUNT(rental_id) INTO v_out
|
||||||
|
FROM inventory LEFT JOIN rental USING(inventory_id)
|
||||||
|
WHERE inventory.inventory_id = p_inventory_id
|
||||||
|
AND rental.return_date IS NULL;
|
||||||
|
|
||||||
|
IF v_out > 0 THEN
|
||||||
|
RETURN FALSE;
|
||||||
|
ELSE
|
||||||
|
RETURN TRUE;
|
||||||
|
END IF;
|
||||||
|
END $$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
SET SQL_MODE=@OLD_SQL_MODE;
|
||||||
|
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||||
|
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||||
|
|
||||||
|
|
BIN
Sakila/sakila.mwb
Normal file
BIN
Sakila/sakila.mwb
Normal file
Binary file not shown.
19
vets/ReadMe.txt
Normal file
19
vets/ReadMe.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Read the description of the vets tables included in this download. It explains how these tables work.
|
||||||
|
|
||||||
|
The data values in these inserts might not exactly match the data values shown in the notes.
|
||||||
|
You can run the demos to check the current values in the tables.
|
||||||
|
|
||||||
|
|
||||||
|
Before running these scripts you need to have created the database: vets and have given your user account permission to use that database.
|
||||||
|
|
||||||
|
It is best to run these two files as scripts from the command line; do not use copy and paste.
|
||||||
|
|
||||||
|
|
||||||
|
The order for running the scripts is
|
||||||
|
1. run the create script - it will remove any previous copy of the tables you might have.
|
||||||
|
2. run the inserts script - it will delete any data from the tables and then do the inserts.
|
||||||
|
|
||||||
|
If later in the semester you want to get back to the original set of data and you have not dropped any of the tables, you can just run the inserts script.
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
vets/Tables.pdf
Normal file
BIN
vets/Tables.pdf
Normal file
Binary file not shown.
607
vets/vets_db_setup.sql
Normal file
607
vets/vets_db_setup.sql
Normal file
|
@ -0,0 +1,607 @@
|
||||||
|
-- Setup
|
||||||
|
|
||||||
|
-- To set up this database run the following command:
|
||||||
|
-- sudo mysql < altgeld_setup.sql
|
||||||
|
|
||||||
|
drop database vets;
|
||||||
|
create database vets;
|
||||||
|
|
||||||
|
GRANT SELECT, INSERT, UPDATE, CREATE, ALTER, DELETE, DROP, REFERENCES, CREATE VIEW
|
||||||
|
ON vets.*
|
||||||
|
TO 'felicia'@'localhost';
|
||||||
|
|
||||||
|
delimiter ;
|
||||||
|
use vets;
|
||||||
|
|
||||||
|
|
||||||
|
-- Creates
|
||||||
|
|
||||||
|
-- remove any prior version of tables
|
||||||
|
drop table if exists vets.vt_exam_details;
|
||||||
|
drop table if exists vets.vt_exam_headers;
|
||||||
|
drop table if exists vets.vt_animals;
|
||||||
|
drop table if exists vets.vt_clients;
|
||||||
|
drop table if exists vets.vt_animal_types;
|
||||||
|
drop table if exists vets.vt_services;
|
||||||
|
drop table if exists vets.vt_staff_pay;
|
||||||
|
drop table if exists vets.vt_staff;
|
||||||
|
|
||||||
|
-- MySQL will not enforce the check constraints
|
||||||
|
-- they are included here to indicate what the values should be
|
||||||
|
|
||||||
|
create table vets.vt_staff (
|
||||||
|
stf_id int unsigned not null
|
||||||
|
, stf_name_last varchar(25) not null
|
||||||
|
, stf_name_first varchar(25) not null
|
||||||
|
, stf_job_title varchar(25) not null
|
||||||
|
, constraint vt_staff_pk primary key (stf_id)
|
||||||
|
, constraint stf_id_range check (stf_id > 0)
|
||||||
|
, constraint job_title_values check
|
||||||
|
( stf_job_title in ('vet', 'vet assnt', 'clerical', 'kennel'))
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
create table vets.vt_staff_pay (
|
||||||
|
stf_id int unsigned not null
|
||||||
|
, stf_ssn char(9) not null
|
||||||
|
, stf_salary numeric(8,2) unsigned not null
|
||||||
|
, stf_hire_date date not null
|
||||||
|
, constraint vt_staff_pay_pk primary key(stf_id)
|
||||||
|
, constraint stf_hire_date_range check (stf_hire_date >= date '1995-01-01')
|
||||||
|
, constraint vt_staff_pay_staff_fk foreign key(stf_id) references vets.vt_staff(stf_id)
|
||||||
|
, constraint stf_salary_range check (stf_salary >= 0)
|
||||||
|
, constraint stf_id2_range check (stf_id > 0)
|
||||||
|
, constraint stf_ssn_un unique (stf_ssn)
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
create table vets.vt_services(
|
||||||
|
srv_id int unsigned not null
|
||||||
|
, srv_list_price numeric(6,2) unsigned not null
|
||||||
|
, srv_desc varchar(50) not null unique
|
||||||
|
, srv_type varchar(25) not null
|
||||||
|
, constraint vt_services_pk primary key (srv_id)
|
||||||
|
, constraint srv_type_ck check (srv_type in
|
||||||
|
('office visit', 'consult', 'medicine', 'treatment'))
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
create table vets.vt_animal_types(
|
||||||
|
an_type varchar(25) not null
|
||||||
|
, constraint an_types_pk primary key (an_type)
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
create table vets.vt_clients(
|
||||||
|
cl_id int unsigned not null
|
||||||
|
, cl_name_last varchar(25) not null
|
||||||
|
, cl_name_first varchar(25) null
|
||||||
|
, cl_address varchar(25) not null
|
||||||
|
, cl_city varchar(25) not null
|
||||||
|
, cl_state char(2) not null
|
||||||
|
, cl_postal_code varchar(12) not null
|
||||||
|
, cl_phone varchar(12) null
|
||||||
|
, constraint vt_clients_pk primary key (cl_id)
|
||||||
|
, constraint cl_id_range check (cl_id > 100)
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
create table vets.vt_animals(
|
||||||
|
an_id int unsigned not null
|
||||||
|
, an_type varchar(25) not null
|
||||||
|
, an_name varchar(25) null
|
||||||
|
, an_dob date not null
|
||||||
|
, cl_id int unsigned not null
|
||||||
|
, constraint vt_animals_pk primary key (an_id)
|
||||||
|
, constraint vt_animals_animal_types_fk foreign key (an_type) references vets.vt_animal_types (an_type)
|
||||||
|
, constraint vt_animals_clients_fk foreign key (cl_id) references vets.vt_clients (cl_id)
|
||||||
|
, constraint an_id_range check (an_id > 0)
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
create table vets.vt_exam_headers(
|
||||||
|
ex_id int unsigned not null
|
||||||
|
, an_id int unsigned not null
|
||||||
|
, stf_id int unsigned not null
|
||||||
|
, ex_date datetime not null
|
||||||
|
, constraint vt_exam_headers_pk primary key (ex_id)
|
||||||
|
, constraint vt_exam_headers_animals_fk foreign key (an_id) references vets.vt_animals (an_id)
|
||||||
|
, constraint vt_exam_headers_staff_fk foreign key (stf_id) references vets.vt_staff (stf_id)
|
||||||
|
, constraint exam_id_range check (ex_id > 0)
|
||||||
|
, constraint exam_date_range check (ex_date >= date '2010-01-01')
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
create table vets.vt_exam_details(
|
||||||
|
ex_id int unsigned not null
|
||||||
|
, line_item int unsigned not null
|
||||||
|
, srv_id int unsigned not null
|
||||||
|
, ex_fee numeric(6,2) unsigned not null
|
||||||
|
, ex_desc varchar(50) not null
|
||||||
|
, constraint evt_exam_details_pk primary key (ex_id, line_item )
|
||||||
|
, constraint evt_exam_details_headers_fk foreign key (ex_id) references vets.vt_exam_headers (ex_id)
|
||||||
|
, constraint evt_exam_details_services_fk foreign key (srv_id) references vets.vt_services (srv_id)
|
||||||
|
, constraint line_item_range check (line_item > 0)
|
||||||
|
, constraint ex_fee_range check (ex_fee >= 0)
|
||||||
|
)engine = INNODB;
|
||||||
|
|
||||||
|
|
||||||
|
-- Inserts
|
||||||
|
|
||||||
|
-- clear earlier versions
|
||||||
|
delete from vt_exam_details;
|
||||||
|
delete from vt_exam_headers;
|
||||||
|
delete from vt_animals;
|
||||||
|
delete from vt_clients;
|
||||||
|
delete from vt_animal_types;
|
||||||
|
delete from vt_services;
|
||||||
|
delete from vt_staff_pay;
|
||||||
|
delete from vt_staff;
|
||||||
|
|
||||||
|
-- staff inserts
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (30, 'Wasilewski', 'Marcin', 'vet');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (15, 'Dolittle', 'Eliza', 'vet');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (20, 'Horn', 'Shirley', 'clerical');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (25, 'Wilkommen', 'Bridgette', 'vet');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (43, 'Halvers', 'Pat', 'kennel');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (29, 'Helfen', 'Sandy', 'vet assnt');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (37, 'Webster', 'Brenda', 'vet assnt');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (38, 'Wabich', 'Rhoda', 'vet');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (52, 'Gordon', 'Dexter', 'vet assnt');
|
||||||
|
|
||||||
|
insert into vt_staff (stf_id, stf_name_last, stf_name_first, stf_job_title)
|
||||||
|
values (55, 'Helfen', 'Sandy', 'vet assnt');
|
||||||
|
|
||||||
|
-- staff pay inserts
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (30, '323445996',99000, '1995-01-06');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (15, '123456789', 40000, '2005-06-01');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (20, '398678765', 35000, '2005-08-01');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (25, '876582345',65000, '2011-06-01');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (43, '325771545', 15500, '2011-08-12');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (37, '323458945', 20000, '2013-01-13');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (38, '322588945', 20000, '2013-01-13');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (52, '325778945', 20000, '2014-08-12');
|
||||||
|
|
||||||
|
insert into vt_staff_pay (stf_id, stf_ssn, stf_salary, stf_hire_date)
|
||||||
|
values (55, '323438454', 37500, '2014-09-26');
|
||||||
|
|
||||||
|
|
||||||
|
-- services inserts
|
||||||
|
insert into vt_services (srv_id, srv_list_price, srv_desc, srv_type)
|
||||||
|
values
|
||||||
|
(101, 50.00, 'Dental Cleaning-Canine', 'treatment')
|
||||||
|
, (105, 80.00, 'Routine Exam-Canine', 'office visit')
|
||||||
|
, (110, 100.00, 'Dental Cleaning-Other', 'treatment')
|
||||||
|
, (225, 75.00, 'Feline PCR Series', 'medicine')
|
||||||
|
, (102, 45.00, 'Dental Cleaning-Feline', 'treatment')
|
||||||
|
, (398, 35.00, 'Followup Exam-Canine', 'office visit')
|
||||||
|
, (400, 10.50, 'Hazardous Materials Disposal', 'treatment')
|
||||||
|
, (106, 75.00, 'Routine Exam-Bird', 'treatment')
|
||||||
|
, (306, 32.00, 'Followup Exam-Bird', 'office visit')
|
||||||
|
, (108, 80.00, 'Routine Exam-Feline', 'office visit')
|
||||||
|
, (308, 45.00, 'Followup Exam-Feline', 'office visit')
|
||||||
|
, (104, 60.00, 'Routine Exam-Reptile', 'office visit')
|
||||||
|
, (341, 25.00, 'Followup Exam-Reptile', 'office visit')
|
||||||
|
, (523, 60.00, 'Routine Exam-Small Mammal', 'office visit')
|
||||||
|
, (524, 25.00, 'Followup Exam-Small Mammal', 'office visit')
|
||||||
|
, (551, 35.50, 'First Feline PCR', 'medicine')
|
||||||
|
, (552, 25.15, 'Second Feline PCR', 'medicine')
|
||||||
|
, (553, 25.85, 'Third Feline PCR', 'medicine')
|
||||||
|
, (112, 25.33, 'Scaly Mite Powder', 'medicine')
|
||||||
|
, (113, 26.00, 'Intestinal Parasite Screen', 'treatment')
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_services (srv_id, srv_list_price, srv_desc, srv_type)
|
||||||
|
values
|
||||||
|
(461, 275.00, 'Feline Behaviour Modification Consultation', 'treatment')
|
||||||
|
, (687, 45.99, 'Vitamin E- Concentrated', 'medicine')
|
||||||
|
, (748, 29.50, 'Preds-liver', 'medicine')
|
||||||
|
, (749, 29.50, 'Preds-chicken', 'medicine')
|
||||||
|
, (602, 222.00, 'General Anaesthesia 1 hour', 'treatment')
|
||||||
|
, (603, 78.00, 'Feline Dental X_ray', 'treatment')
|
||||||
|
, (604, 109.00, 'Dental Scaling', 'treatment')
|
||||||
|
, (605, 535.00, 'Tooth extraction Level 1', 'treatment')
|
||||||
|
, (606, 40.00, 'Tooth extraction Level 2', 'treatment')
|
||||||
|
, (607, 57.00, 'Tooth extraction Level 3', 'treatment')
|
||||||
|
, (612, 25.91, 'Buprenex oral drops 1 ml', 'medicine')
|
||||||
|
, (613, 47.00, 'Hospital stay- short', 'treatment')
|
||||||
|
, (615, 78.30, 'Antibiotics', 'medicine')
|
||||||
|
, (625, 155.00, 'CBC and scan', 'treatment')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- animal type inserts
|
||||||
|
insert into vt_animal_types( an_type)
|
||||||
|
Values
|
||||||
|
('bird')
|
||||||
|
, ('porcupine' )
|
||||||
|
, ('capybara')
|
||||||
|
, ('cat')
|
||||||
|
, ('crocodilian')
|
||||||
|
, ('dog')
|
||||||
|
, ('dormouse' )
|
||||||
|
, ('hamster')
|
||||||
|
, ('hedgehog')
|
||||||
|
, ('lizard')
|
||||||
|
, ('olinguito')
|
||||||
|
, ('snake')
|
||||||
|
, ('turtle')
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- clients inserts
|
||||||
|
insert into vt_clients (cl_id, cl_name_last, cl_name_first, cl_address, cl_city, cl_state, cl_postal_code, cl_phone)
|
||||||
|
values
|
||||||
|
(254, 'Boston', 'Edger', 'POB 2', 'Boston', 'MA', 21555, null)
|
||||||
|
, (411, 'Carter', 'James', '2 Marshall Ave', 'Big Rock', 'AR', '71601', '510.258.4546')
|
||||||
|
, (1825, 'Harris', 'Eddie', '2 Marshall Ave', 'Big Rock', 'AR', '71601', null)
|
||||||
|
, (1852, 'Dalrymple', 'Jack', '2 Marshall Ave', 'Big Rock', 'ND', '58503', '701.328.2725')
|
||||||
|
, (3423, 'Hawkins', 'Coleman', '23 Ruby Lane', 'Springfield', 'OH', '45502', '937.258.5645')
|
||||||
|
, (3560, 'Monk', 'Theo', '345 Post Street', 'New York', 'NY', '10006', '212.582.6245')
|
||||||
|
, (3561, 'Pickett', 'Wilson', 'POB 397', 'New York', 'NY', '10006', '212.584.9871')
|
||||||
|
, (4087, 'Turrentine', 'Stanley', '2920 Zoo Drive', 'San Diego', 'CA', '92101', '619.231.1515')
|
||||||
|
, (4534, 'Montgomery', 'Wes', 'POB 345', 'Dayton', 'OH', '45402', null )
|
||||||
|
, (5686, 'Biederbecke', null, '50 Phelan Ave', 'Springfield', 'IL', '62701', '217.239.6945')
|
||||||
|
, (5689, 'Biederbecke', null, '50 Phelan Ave', 'San Francisco', 'CA', '94112', '415.239.6945')
|
||||||
|
, (5698, 'Biederbecke', 'Sue', '50 Phelan Ave', 'Springfield', 'IL', '62701', '217.239.6875')
|
||||||
|
, (5699, 'Biederbecke', 'Sam', '549 Market Ave', 'San Francisco', 'CA', '94101', '415.239.6875')
|
||||||
|
, (6426, 'Hawkins', 'Coleman', '26 Ruby Lane', 'Springfield', 'OH', '45502', null)
|
||||||
|
, (6897, 'Drake', 'Donald', '50 Phelan Ave', 'Springfield', 'MO', '65802', null)
|
||||||
|
, (7152, 'Brubeck', 'Dave', '50 Green St', 'Spring Valley', 'MA', '21579', '258.257.2727')
|
||||||
|
, (7212, 'Davis', 'Donald', '124 Fifth', 'San Francisco', 'NM', '87801', null)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- animal inserts
|
||||||
|
|
||||||
|
insert into vt_animals ( an_id, cl_id, an_name, an_type, an_dob)
|
||||||
|
values
|
||||||
|
(10002, 3560, 'Gutsy', 'cat', '2010-04-15' )
|
||||||
|
, (11015, 3560, 'Kenny', 'bird', '2012-02-23' )
|
||||||
|
, (11025, 3560, null, 'bird', '2012-02-01' )
|
||||||
|
, (11028, 3560, null, 'bird', '2015-10-01' )
|
||||||
|
, (11029, 3560, null, 'bird', '2015-10-01' )
|
||||||
|
, (12035, 3560, 'Mr Peanut', 'bird', '1995-02-28' )
|
||||||
|
, (12038, 3560, 'Gutsy', 'porcupine', '2012-04-29' )
|
||||||
|
, (15001, 3561, 'Big Mike', 'turtle', '2010-02-02' )
|
||||||
|
, (15002, 5699, 'George', 'turtle', '1998-02-02' )
|
||||||
|
, (15165, 411, 'Burgess', 'dog', '2005-11-20' )
|
||||||
|
, (15401, 411, 'Pinkie', 'lizard', '2010-03-15' )
|
||||||
|
, (16002, 3423, 'Fritz', 'porcupine', '2015-05-25' )
|
||||||
|
, (16003, 1825, 'Ursula', 'cat', '2013-02-06' )
|
||||||
|
, (16043, 1825, 'Ursula', 'dog', '2014-06-06' )
|
||||||
|
, (16044, 1825, 'Triton', 'dog', '2014-06-06' )
|
||||||
|
, (17002, 5699, 'Fritzchen', 'porcupine', '2012-06-02' )
|
||||||
|
, (17025, 3561, '25', 'lizard', '2013-01-10' )
|
||||||
|
, (17026, 7152, '3P#_26', 'lizard', '2010-01-10' )
|
||||||
|
, (17027, 7152, '3P#_25', 'lizard', '2010-01-10' )
|
||||||
|
, (19845, 6426, 'Pinkie', 'dog', '2009-02-02' )
|
||||||
|
, (21001, 411, 'Yoggie', 'hedgehog', '2009-05-22' )
|
||||||
|
, (21002, 1825, 'Edger', 'hedgehog', '2002-10-02' )
|
||||||
|
, (21003, 6426, 'Calvin Coolidge', 'dog', '2014-06-18' )
|
||||||
|
, (21004, 3561, 'Gutsy', 'snake', '2011-05-12' )
|
||||||
|
, (21005, 3423, 'Koshka', 'dormouse', '2011-03-06' )
|
||||||
|
, (21006, 3423, 'Koshka', 'hamster', '2011-06-06' )
|
||||||
|
, (21007, 1852, 'Pop 22', 'snake', '2010-06-12' )
|
||||||
|
, (21205, 5689, 'Manfried', 'dog', '2015-03-30' )
|
||||||
|
, (21305, 4087, 'Spot', 'dog', '2014-07-27' )
|
||||||
|
, (21306, 4087, 'Shadow', 'dog', '2014-07-27' )
|
||||||
|
, (21307, 4087, 'Buddy', 'dog', '2014-07-27' )
|
||||||
|
, (21314, 4087, 'Adalwine', 'cat', '2013-06-11' )
|
||||||
|
, (21315, 4534, 'Baldric', 'cat', '2013-06-11' )
|
||||||
|
, (21316, 5698, 'Etta', 'cat', '2010-06-11' )
|
||||||
|
, (21317, 5698, 'Manfried', 'cat', '2011-06-11' )
|
||||||
|
, (21318, 5698, 'Waldrom', 'cat', '2012-06-11' )
|
||||||
|
, (21320, 1852, 'Morris', 'olinguito', '2014-06-11' )
|
||||||
|
, (21321, 1852, 'Morton', 'olinguito', '2014-06-03' )
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- exam inserts
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2228, 21306, 38, '2015-04-04 12:30:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2228, 1, 398, 30.00, 'Follow-up exam' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2205, 21307, 38, '2015-04-08 10:30:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2205, 1, 105, 75.00, 'Routine exam' )
|
||||||
|
, (2205, 2, 101, 50.00, 'Dental' )
|
||||||
|
, (2205, 3, 602, 200.00, 'Anaesthesia' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2289, 21320, 38, '2015-04-11 13:00:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2289, 1, 523, 275.00, 'Routine exam' );
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2290, 21320, 38, '2015-04-11 17:00:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2290, 1, 524, 275.00, 'Follow-up exam' )
|
||||||
|
, (2290, 2, 613, 41.00, 'Overnight observation' );
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2300, 21316, 38, '2015-05-08 09:15:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2300, 1, 108, 75.00, 'Routine exam' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2352, 10002, 38, '2015-05-12 09:15:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2352, 1, 108, 75.00, 'Routine exam' )
|
||||||
|
, (2352, 2, 615, 75.00, 'Antibiotics' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2389, 21006, 38, '2015-05-20 09:45:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2389, 1, 523, 60.00, 'Initial exam' )
|
||||||
|
, (2389, 5, 110, 50.00, 'Dental');
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (2400, 12038, 38, '2015-06-02 13:00:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (2400, 1, 461, 275.00, 'Aggressive behaviour' );
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3002, 11028, 38, '2015-10-02 13:00:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3002, 1, 106, 60.00, 'Initial exam' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3003, 11029, 38, '2015-10-02 13:00:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3003, 1, 106, 60.00, 'Initial exam' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4243, 16002, 38, '2015-06-08 15:30:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4243, 1, 461, 275.00, 'Aggressive behaviour' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4255, 16002, 38, '2015-07-08 15:30:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4255, 1, 461, 275.00, 'Aggressive behaviour' );
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4612, 21317, 15, '2015-07-23 08:30:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4612, 1, 602, 222.00, 'Dental anaesthesia' )
|
||||||
|
, (4612, 2, 603, 78.00, 'Dental' )
|
||||||
|
, (4612, 3, 606, 40.00, 'Dental tooth 1' )
|
||||||
|
, (4612, 4, 612, 25.91, 'As needed at home' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4514, 15002, 29, '2015-08-10 10:45:00' );
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4514, 1, 104, 30.00, 'Routine exam' )
|
||||||
|
, (4514, 2, 112, 15.00, 'Mite infection' )
|
||||||
|
, (4514, 3, 113, 25.00, 'Parasite screen' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4203, 16002, 29, '2015-08-03 14:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4203, 1, 524, 20.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4282, 21001, 15, '2015-08-23 10:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4282, 1, 523, 60.00, 'Yearly checkup')
|
||||||
|
, (4282, 2, 110, 50.00, 'Minor buildup')
|
||||||
|
, (4282, 3, 615, 25.25, 'Antibiotic half dosage');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4233, 16002, 29, '2015-09-03 14:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4233, 1, 524, 20.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3105, 17002, 29, '2015-10-10 9:15:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3105, 1, 523, 50.50, 'Checkup')
|
||||||
|
, (3105, 2, 110, 150.00, 'Dental');
|
||||||
|
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3010, 17026, 29, '2015-10-22 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3010, 1, 104, 25.00, 'Routine exam')
|
||||||
|
, (3010, 2, 605, 535.00, 'Tooth extraction');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3001, 17027, 29, '2015-10-24 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3001, 1, 104, 25.00, 'Routine exam');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3202, 17025, 29, '2015-10-03 14:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3202, 1, 341, 20.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3513, 15401, 15, '2015-11-06 10:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3513, 1, 104, 30.00, 'Yearly checkup')
|
||||||
|
, (3513, 2, 110, 75.00, 'Repeat treatment');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3552, 16003, 15, '2015-11-10 10:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3552, 1, 308, 2.25, 'Dental follow-up- phone')
|
||||||
|
, (3552, 3, 615, 25.25, 'Antibiotic half dosage');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3304, 17027, 15, '2015-11-06 10:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3304, 1, 341, 25.00, 'Yearly checkup')
|
||||||
|
, (3304, 2, 113, 25.00, 'Test for repeat infection');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3306, 17025, 29, '2015-11-06 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3306, 1, 104, 30.00, 'Routine exam')
|
||||||
|
, (3306, 2, 687, 45.00, 'Liquid form')
|
||||||
|
, (3306, 3, 112, 25.00, 'Parasite external');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3390, 19845, 15, '2015-11-22 09:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3390, 1, 105, 55.00, 'Yearly checkup')
|
||||||
|
, (3390, 2, 101, 70.00, 'Major build-up');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3411, 17025, 29, '2015-12-29 14:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3411, 1, 341, 20.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3412, 17025, 29, '2015-12-30 14:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3412, 1, 341, 20.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3413, 16003, 15, '2015-12-01 16:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3413, 1, 308, 5.00, 'Follow up checkup');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3612, 16003, 15, '2015-12-23 08:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3612, 1, 602, 222.00, 'Dental anaesthesia')
|
||||||
|
, (3612, 2, 603, 78.00, 'Dental')
|
||||||
|
, (3612, 3, 604, 109.00, 'Dental- mild')
|
||||||
|
, (3612, 4, 625, 155.00, 'Dental -pre tests')
|
||||||
|
, (3612, 5, 606, 40.00, 'Dental tooth 1')
|
||||||
|
, (3612, 6, 607, 57.00, 'Dental tooth 2')
|
||||||
|
, (3612, 7, 612, 25.91, 'As needed at home')
|
||||||
|
, (3612, 8, 613, 47.00, 'Feline cage')
|
||||||
|
, (3612, 9, 615, 78.30, 'In-patient');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3392, 21003, 15, '2015-12-26 09:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3392, 1, 398, 30.00, 'Weight loss Follow up ')
|
||||||
|
, (3392, 2, 400, 21.00, 'Discard first sample')
|
||||||
|
, (3392, 3, 113, 45.00, 'Retest for parasites' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3393, 16002, 29, '2015-12-23 12:15:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3393, 1, 748, 29.50, 'Rat ulcer recurrence')
|
||||||
|
, (3393, 3, 749, 0.00, 'Rat ulcer recurrence');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3409, 17027, 29, '2015-12-27 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3409, 1, 104, 25.00, 'Routine exam');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3486, 21005, 15, '2015-12-31 13:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3486, 1, 461, 275.00, 'Aggressive behaviour' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4101, 15001, 15, '2016-01-02 13:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4101, 1, 104, 60.00, 'Routine exam' )
|
||||||
|
, (4101, 2, 615, 75.00, 'Possible infection' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4102, 15002, 15, '2016-01-08 13:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4102, 1, 104, 60.00, 'Routine exam' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (4103, 16002, 38, '2016-01-08 15:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (4103, 1, 461, 275.00, 'Aggressive behaviour' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3104, 12035, 38, '2016-01-09 16:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3104, 1, 106, 75, 'Moult' )
|
||||||
|
, (3104, 2, 613, 47, 'Confine for the first molt' );
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3325, 17026, 29, '2016-01-15 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3325, 1, 104, 25.00, 'Routine exam')
|
||||||
|
, (3325, 2, 604, 59.00, 'Dental');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3420, 16003, 15, '2016-01-01 16:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3420, 1, 108, 80.00, 'Yearly checkup');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3494, 15001, 25, '2016-01-22 09:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3494, 1, 104, 30, 'Follow-up checkup');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3288, 15001, 25, '2016-01-31 09:00:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3288, 1, 104, 30, 'Checkup')
|
||||||
|
, (3288, 2, 112, 25, 'Mite infestation')
|
||||||
|
, (3288, 3, 687, 45, 'Shell softening');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3322, 16002, 29, '2016-02-10 9:15:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3322, 1, 748, 29.50, 'Rat ulcer recurrence');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3321, 16002, 29, '2016-02-17 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3321, 1, 748, 0.00, 'Rat ulcer recurrence');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3324, 17025, 29, '2016-02-25 10:45:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3324, 1, 104, 30.00, 'Routine exam')
|
||||||
|
, (3324, 2, 687, 45.00, 'Liquid form')
|
||||||
|
, (3324, 3, 112, 25.00, 'Parasite external');
|
||||||
|
|
||||||
|
insert into vt_exam_headers(ex_id, an_id, stf_id, ex_date)
|
||||||
|
values (3323, 16002, 29, '2016-02-25 14:30:00');
|
||||||
|
insert into vt_exam_details(ex_id, line_item, srv_id, ex_fee, ex_desc)
|
||||||
|
values (3323, 1, 524, 20.00, 'Follow-up on parasites')
|
||||||
|
, (3323, 3, 687, 45.00, 'Follow-up on parasites');
|
||||||
|
|
||||||
|
-- End
|
Loading…
Add table
Add a link
Reference in a new issue