


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















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). 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), DROP COLUMN Genre,
CHANGE 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-
Height - decimal number BirthDate - date Delete the following rows: 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';
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 CHECK (ID > 0 AND ID <= 50000), Title VARCHAR(50), Rating CHAR(4), ReleaseDate DATE, Budget DECIMAL(8,2) ); 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 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 CREATE TABLE Student ( ID SMALLINT Unsigned AUTO_INCREMENT PRIMARY KEY, FirstName VARCHAR(20) NOT NULL, LastName VARCHAR(30) NOT NULL, Street VARCHAR(50) NOT NULL, City VARCHAR(20) NOT NULL, State CHAR(2) NOT NULL DEFAULT 'TX', Zip MEDIUMINT UNSIGNED NOT NULL CHECK (Zip >= 0 AND Zip <= 16000000), Phone CHAR(10) NOT NULL, Email VARCHAR(30) UNIQUE ); Create a Horse table with the following columns, data types, and constraints. NULL is allowed unless 'not NULL' is explicitly stated.
The database contains a Student table, with columns: ID - integer, primary key FirstName - variable-length string LastName - variable-length string Create a third table, named LessonSchedule, with columns: HorseID - integer with range 0 to 65 thousand, not NULL, foreign key references Horse(ID) StudentID - integer with range 0 to 65 thousand, foreign key references Student(ID) LessonDateTime - date/time, not NULL Primary key is (HorseID, LessonDateTime) 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.
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) ); CREATE TABLE LessonSchedule ( HorseID SMALLINT UNSIGNED NOT NULL, StudentID SMALLINT UNSIGNED, LessonDateTime DATETIME NOT NULL, PRIMARY KEY (HorseID, LessonDateTime), FOREIGN KEY (HorseID) REFERENCES Horse(ID) ON DELETE CASCADE, FOREIGN KEY (StudentID) REFERENCES Student(ID) ON DELETE SET NULL );
ROLLBACK TO SAVEPOINT my_savepoint; SELECT * FROM actor; 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. 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 RatingDescription—variable-length string The Movie table should have the following columns: Title—variable-length string, maximum 30 characters RatingCode—variable-length string, maximum 5 characters Write a SQL statement to create the Movie table. Designate the RatingCode column in the Movie table as a foreign key to the RatingCode column in the Rating table. CREATE TABLE Movie( Title VARCHAR(30), RatingCode VARCHAR(5),
ADD Score DECIMAL(3,1); The Movie table has the following columns: ID—integer, primary key Title—variable-length string Genre—variable-length string RatingCode—variable-length string Year—integer Write a SQL statement to create a view named MyMovies that contains the Title, Genre, and Year columns for all movies. Ensure your result set returns the columns in the order indicated. CREATE VIEW MyMovies AS SELECT Title, Genre, Year FROM Movie; A database has a view named MovieView.
Write a SQL statement to delete the view named MovieView from the database. DROP VIEW MovieView; The Movie table has the following columns: ID—integer Title—variable-length string Genre—variable-length string RatingCode—variable-length string Year—integer Write a SQL statement to modify the Movie table to make the ID column the primary key. ALTER TABLE Movie ADD PRIMARY KEY (ID); The Movie table has the following columns: ID—integer, primary key Title—variable-length string Genre—variable-length string
RatingCode—variable-length string Year—integer Write a SQL statement to create an index named idx_year on the Year column of the Movie table. CREATE INDEX idx_year ON Movie (Year); The Movie table has the following columns: ID—integer, primary key, auto-increment Title—variable-length string Genre—variable-length string RatingCode—variable-length string Year—integer The following data needs to be added to the Movie table:
Title | Genre | RatingCode | Year Pride and Prejudice | Romance | G | 2005 Write a SQL statement to insert the indicated data into the Movie table. INSERT INTO Movie (Title, Genre, RatingCode, Year) VALUES ('Pride and Prejudice', 'Romance', 'G', 2005); The Movie table has the following columns: ID—integer, primary key Title—variable-length string Genre—variable-length string RatingCode—variable-length string Year—integer Write a SQL statement to delete the row with the ID value of 3 from the Movie table. DELETE FROM Movie