Docsity

SQL Queries and Database Management, Exams of Service Management

Toggle sidebar
bg1
Queries
The Movie table has the following columns:
ID - positive integer
Title - variable-length string
Genre - variable-length string
RatingCode - variable-length string
Year - integer
Write ALTER statements to make the following modifications to the Movie
table:
Add a Producer column with VARCHAR data type (max 50 chars).
ALTER TABLE Movie ADD Producer VARCHAR(50);
The Movie table has the following columns:
ID - positive integer
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download SQL Queries and Database Management and more Exams Service Management in PDF only on Docsity!

Queries

The Movie table has the following columns: ID - positive integer Title - variable-length string Genre - variable-length string RatingCode - variable-length string Year - integer Write ALTER statements to make the following modifications to the Movie table: Add a Producer column with VARCHAR data type (max 50 chars). ALTER TABLE Movie ADD Producer VARCHAR(50); The Movie table has the following columns: ID - positive integer

Title - variable-length string Genre - variable-length string RatingCode - variable-length string Year - integer Write ALTER statements to make the following modifications to the Movie table: Remove the Genre column. ALTER TABLE Movie DROP COLUMN Genre; The Movie table has the following columns: ID - positive integer Title - variable-length string Genre - variable-length string RatingCode - variable-length string

  • Remove the Genre column.
  • Change the Year column's name to ReleaseYear, and change the data type to SMALLINT. ALTER TABLE Movie ADD Producer VARCHAR(50); ALTER TABLE Movie DROP COLUMN Genre; ALTER TABLE Movie CHANGE COLUMN Year ReleaseYear SMALLINT; 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. BirthDate - date, must be on or after Jan 1, 2015 Insert the following data into the Horse table: RegisteredName Breed Height BirthDate

Babe Quarter Horse 15.3 2015-02- Independence Holsteiner 16.0 2017-03- Ellie Saddlebred 15.0 2016-12- NULL Egyptian Arab 14.9 2019-10- INSERT INTO Horse (RegisteredName, Breed, Height, BirthDate) VALUES ('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'); 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.

Change the registered name to Lady Luck and birth date to May 1, 2015 for horse with ID 4. UPDATE Horse SET RegisteredName = 'Lady Luck', BirthDate = '2015-05-01' WHERE ID = 4; 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. BirthDate - date, must be ≥ Jan 1, 2015 Make the following updates: Change every horse breed to NULL for horses born on or after December 22,

UPDATE Horse SET Breed = NULL WHERE BirthDate >= '2016-12-22'; 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. BirthDate - date, must be ≥ Jan 1, 2015 Make the following updates:

  • Change the height to 15.6 for horse with ID 2.
  • 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.
  • Horse with ID 5.
  • All horses with breed Holsteiner or Paint.
  • All horses born before March 13, 2013. DELETE FROM Horse WHERE ID = 5; DELETE FROM Horse WHERE Breed IN ('Holsteiner', 'Paint'); DELETE FROM Horse WHERE BirthDate < '2013-03-13'; 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 - date

Delete the following rows:

  • Horse with ID 5. DELETE FROM Horse WHERE ID = 5; 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 - date Delete the following rows:
  • All horses with breed Holsteiner or Paint. DELETE FROM Horse WHERE Breed IN ('Holsteiner', 'Paint');

ID - integer, primary key RegisteredName - variable-length string Breed - variable-length string Height - decimal number BirthDate - date Write 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. SELECT RegisteredName, Height, BirthDate FROM Horse WHERE (Height BETWEEN 15.0 AND 16.0) OR (BirthDate >= '2020-01-01'); Create a Movie table with the following columns: ID - positive integer with maximum value of 50, Title - variable-length string with up to 50 characters Rating - fixed-length string with 4 characters

ReleaseDate - date Budget - decimal value representing a cost of up to 999,999 dollars, with 2 digits for cents CREATE TABLE Movie ( ID SMALLINT UNSIGNED PRIMARY KEY CHECK (ID <= 50000), Title VARCHAR(50), Rating CHAR(4), ReleaseDate DATE, Budget DECIMAL(8,2) CHECK (Budget <= 999999.99) ); Create a Student table with the following column names, data types, and constraints: 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

RegisteredName - variable-length string with max 15 chars, not NULL Breed - variable-length string with max 20 chars, must be one of the following: Egyptian Arab, Holsteiner, Quarter Horse, Paint, Saddlebred Height - number with 3 significant digits and 1 decimal place, must be ≥ 10. and ≤ 20. BirthDate - date, must be ≥ Jan 1, 2015 CREATE TABLE Horse ( ID SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, RegisteredName VARCHAR(15) NOT NULL, Breed VARCHAR(20) CHECK (Breed IN ('Egyptian Arab', 'Holsteiner', 'Quarter Horse', 'Paint', 'Saddlebred')), Height DECIMAL(3,1) CHECK (Height >= 10.0 AND Height <= 20.0), BirthDate DATE CHECK (BirthDate >= '2015-01-01') ); Two tables are created: Horse with columns: ID - integer, primary key

RegisteredName - variable-length string Student with columns: ID - integer, primary key FirstName - variable-length string LastName - variable-length string Create 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 key If 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. Notes: Table and column names are case sensitive in the auto-grader.

-- Start the transaction START TRANSACTION; -- 1. Insert a new actor INSERT INTO actor (actor_id, first_name, last_name, last_update) VALUES (999, 'NICOLE', 'STREEP', '2021-06-01 12:00:00'); -- 2. Set a SAVEPOINT SAVEPOINT my_savepoint; -- 3. Delete the actor with first name 'CUBA' DELETE FROM actor WHERE first_name = 'CUBA'; -- 4. Select all actors SELECT * FROM actor; -- 5. Roll back to the savepoint ROLLBACK TO my_savepoint; -- 6. Select all actors a second time SELECT * FROM actor; -- End the transaction (optional, based on the desired outcome) COMMIT; The Member table will have the following columns: ID—positive integer FirstName—variable-length string with up to 100 characters MiddleInitial—fixed-length string with 1 character

LastName—variable-length string with up to 100 characters DateOfBirth—date AnnualPledge—positive decimal value representing a cost of up to $999,999, with 2 digits for cents Write a SQL statement to create the Member table. Do not add any additional constraints to any column beyond what is stated. CREATE TABLE Member ( ID INT UNSIGNED, FirstName VARCHAR(100), MiddleInitial CHAR(1), LastName VARCHAR(100), DateOfBirth DATE, AnnualPledge DECIMAL(8,2) UNSIGNED ); The Rating table has the following columns: RatingCode—variable-length string, primary key