DAT380 Advanced Database Architecture
DAT380 Advanced Database Architecture
DAT380 covers database concepts. Topics include data structures, schemas and standards in addition to centralized and client server systems, server system architectures, parallel systems, distributed systems.
-
DAT/380 Week 5 LAB 5.7 - Implement supertype and subtype entities (Sakila)
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 5 LAB 5.7 - Implement supertype and subtype entities (Sakila)
Refer to the customer and staff tables of the Sakila database. These tables have many columns in common and represent similar entities. Convert the customer and staff entities into subtypes of a new supertype person:
In the center is the person entity, with primary key person_id and additional attributes first_name, last_name, email, active, and last_update. The person entity contains subtype entities staff and customer. The staff entity has primary key person_id and additional attributes picture, username, and password. The customer entity has primary key person_id and additional attribute create_date. Cardinality does not appear after the primary keys and attributes. On the left is the address entity, connected to the person entity by the belongs_to relationship. Belongs_to has cardinality 1(1) on the address side and M(0) on the person side. On the right is the store entity, connected to the person entity by the works_at relationship. Works_at has cardinality 1(1) on the store side and M(0) on the person side.
The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names:
All lower case
Underscore separator between root and suffix
Foreign keys have the same name as referenced primary keyImplement supertype and subtype entities as person, customer, and staff tables with primary key person_id.
Implement attributes as columns:
All columns are NOT NULL.
The person_id columns have data type SMALLINT UNSIGNED.
The last_update and create_date columns have data type TIMESTAMP.
The picture column has data type BLOB.
All other columns have data type VARCHAR(20).Implement the dependency relationships between subtype and supertype entities as foreign keys:
The person_id columns of customer and staff become foreign keys referring to person.
Specify CASCADE actions for both relationships.Implement the belongs_to and works_at relationships as foreign keys:
belongs_to becomes an address_id foreign key in person referring to address.
works_at becomes a store_id foreign key in staff referring to store.
Specify RESTRICT actions for both relationships.The address and store tables, with primary keys address_id and store_id, are pre-defined in the zyLab environment. Foreign keys must have the same data types as the referenced primary keys:
address_id has data type SMALLINT UNSIGNED.
store_id has data type TINYINT UNSIGNED.If you execute your solution with the Sakila database, you must first drop customer, staff, and all constraints that refer to these tables. Use the following statements with Sakila only, not in the zyLab environment:
Learn More
DROP TABLE customer, staff;
ALTER TABLE payment
DROP CONSTRAINT fk_payment_customer,
DROP CONSTRAINT fk_payment_staff;
ALTER TABLE rental
DROP CONSTRAINT fk_rental_customer,
DROP CONSTRAINT fk_rental_staff;
ALTER TABLE store
DROP CONSTRAINT fk_store_staff; -
DAT/380 Week 5 LAB 5.6 - Implement independent entity (Sakila)
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 5 LAB 5.6 - Implement independent entity (Sakila)
Implement a new independent entity phone in the Sakila database. Attributes and relationships are shown in the following diagram:
The phone entity appears on the right. The phone entity contains four attributes, each followed by cardinality information: phone_id 1-1(1), country_code M-1(1), phone_numer M-1(1), and phone_type M-1(0). Three entities appear on the left: store, staff, and customer, connected to the phone entity by three identical relationships. The three relationships are named 'has' and have cardinality 1(0) on both sides.
The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names:
All lower case
Underscore separator between root and suffix
Foreign keys have the same name as referenced primary keyWrite CREATE TABLE and ALTER TABLE statements that:
1. Implement the entity as a new phone table.
2. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables.
3. Remove the existing phone column from the Sakila address table.Step 2 requires adding a foreign key constraint to an existing table. Ex:
ALTER TABLE customer
ADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id)
ON DELETE SET NULL
ON UPDATE CASCADE;
Specify data types as follows:
phone_id, phone_number, and country_code have data type INT.
phone_type has date type VARCHAR(12) and contains strings like 'Home', 'Mobile', and 'Other'.Apply these constraints:
Learn More
NOT NULL constraints correspond to cardinalities on the diagram above.
Foreign key actions are SET NULL for delete rules and CASCADE for update rules.
Specify a suitable column as the phone table primary key. -
DAT/380 Week 4 LAB 4.7 - Select number of movies grouped by year
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 4 LAB 4.7 - Select number of movies grouped by year
The Movie table has the following columns:
ID - integer, primary key
Title - variable-length string
Genre - variable-length string
RatingCode - variable-length string
Year - integerWrite a SELECT statement to select the year and the total number of movies for that year.
Hint: Use the COUNT() function and GROUP BY clause
Learn More -
DAT/380 Week 4 LAB 4.6 - Select lesson schedule with inner join
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 4 LAB 4.6 - Select lesson schedule with inner join
The database has three tables for tracking horse-riding lessons:
Horse with columns:
ID - primary key
RegisteredName
Breed
Height
BirthDateStudent with columns:
ID - primary key
FirstName
LastName
Street
City
State
Zip
Phone
EmailAddressLessonSchedule with columns:
HorseID - partial primary key, foreign key references Horse(ID)
StudentID - foreign key references Student(ID)
LessonDateTime - partial primary keyWrite a SELECT statement to create a lesson schedule with the lesson date/time, horse ID, and the student's first and last names. Order the results in ascending order by lesson date/time, then by horse ID. Unassigned lesson times (student ID is NULL) should not appear in the schedule.
Hint: Perform a join on the Student and LessonSchedule tables, matching the student IDs.
Learn More -
DAT/380 Week 3 LAB 3.16 - Select horses with logical operators
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.16 - Select horses with logical operators
The Horse table has the following columns:
ID - integer, primary key
RegisteredName - variable-length string
Breed - variable-length string
Height - decimal number
BirthDate - dateWrite a SELECT statement to select the registered name, height, and birth date for only horses that have a height between 15.0 and 16.0 (inclusive) or have a birth date on or after January 1, 2020.
Learn More -
DAT/380 Week 3 LAB 3.15 - Delete rows from Horse table
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.15 - Delete rows from Horse table
The Horse table has the following columns:
ID - integer, auto increment, primary key
RegisteredName - variable-length string
Breed - variable-length string
Height - decimal number
BirthDate - dateDelete the following rows:
Learn More
Horse with ID 5.
All horses with breed Holsteiner or Paint.
All horses born before March 13, 2013. -
DAT/380 Week 3 LAB 3.14 - Update rows in Horse table
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.14 - Update rows in Horse table
The Horse table has the following columns:
ID - integer, auto increment, primary key
RegisteredName - variable-length string
Breed - variable-length string, must be one of the following: Egyptian Arab, Holsteiner, Quarter Horse, Paint, Saddlebred
Height - decimal number, must be ≥ 10.0 and ≤ 20.0
BirthDate - date, must be ≥ Jan 1, 2015
Make the following updates:Change the height to 15.6 for horse with ID 2.
Learn More
Change the registered name to Lady Luck and birth date to May 1, 2015 for horse with ID 4.
Change every horse breed to NULL for horses born on or after December 22, 2016. -
DAT/380 Week 3 LAB 3.13 - Insert rows into Horse table
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.13 - Insert rows into Horse table
The Horse table has the following columns:
ID - integer, auto increment, primary key
RegisteredName - variable-length string
Breed - variable-length string, must be one of the following: Egyptian Arab, Holsteiner, Quarter Horse, Paint, Saddlebred
Height - decimal number, must be between 10.0 and 20.0
BirthDate - date, must be on or after Jan 1, 2015Insert the following data into the Horse table:
Learn More
RegisteredName Breed Height BirthDate
Babe Quarter Horse 15.3 2015-02-10
Independence Holsteiner 16.0 2017-03-13
Ellie Saddlebred 15.0 2016-12-22
NULL Egyptian Arab 14.9 2019-10-12 -
DAT/380 Week 3 LAB 3.12 - Create LessonSchedule table with FK constraints
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.12 - Create LessonSchedule table with FK constraints
Two tables are created:
Horse with columns:
ID - integer, primary key
RegisteredName - variable-length stringStudent with columns:
ID - integer, primary key
FirstName - variable-length string
LastName - variable-length stringCreate the LessonSchedule table with columns:
HorseID - integer with range 0 to 65 thousand, not NULL, partial primary key, foreign key references Horse(ID)
StudentID - integer with range 0 to 65 thousand, foreign key references Student(ID)
LessonDateTime - date/time, not NULL, partial primary keyIf a row is deleted from Horse, the rows with the same horse ID should be deleted from LessonSchedule automatically.
If a row is deleted from Student, the same student IDs should be set to NULL in LessonSchedule automatically.
Note: Table and column names are case sensitive in the auto-grader.
CREATE TABLE Horse (
ID SMALLINT UNSIGNED AUTO_INCREMENT,
RegisteredName VARCHAR(15),
PRIMARY KEY (ID)
);CREATE TABLE Student (
ID SMALLINT UNSIGNED AUTO_INCREMENT,
FirstName VARCHAR(20),
LastName VARCHAR(30),
PRIMARY KEY (ID)
);-- Your SQL statements go here
Learn More -
DAT/380 Week 3 LAB 3.11 - Create Student table with constraints
Regular Price: $5.00
Special Price $3.00
DAT/380 Week 3 LAB 3.11 - Create Student table with constraints
Create a Student table with the following column names, data types, and constraints:
Learn More
ID - integer with range 0 to 65 thousand, auto increment, primary key
FirstName - variable-length string with max 20 chars, not NULL
LastName - variable-length string with max 30 chars, not NULL
Street - variable-length string with max 50 chars, not NULL
City - variable-length string with max 20 chars, not NULL
State - fixed-length string of 2 chars, not NULL, default "TX"
Zip - integer with range 0 to 16 million, not NULL
Phone - fixed-length string of 10 chars, not NULL
Email - variable-length string with max 30 chars, must be unique