




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of sql statements and queries related to the creation, modification, and manipulation of database tables and views. It covers topics such as table creation, column addition, view creation, index creation, data insertion, deletion, and updating. The correct sql statements to perform these database operations, demonstrating proficiency in sql syntax and database management. By studying this document, students can gain a deeper understanding of sql concepts, practice their sql skills, and prepare for assessments or exams related to database management and sql programming.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





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. - correct answer ✔CREATE TABLE Member ( ID INT UNSIGNED, FirstName VARCHAR(100), MiddleInitial CHAR(1), LastName VARCHAR(100), DateOfBirth DATE, AnnualPledge DECIMAL(9, 2) ); 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. - correct answer ✔CREATE TABLE Movie ( Title VARCHAR(30), RatingCode VARCHAR(5), FOREIGN KEY (RatingCode) REFERENCES Rating(RatingCode) ); 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 A new column must be added to the Movie table: Column name: Score Data type: decimal(3,1) Write a SQL statement to add the Score column to the Movie table. - correct answer ✔ALTER TABLE Movie ADD Score DECIMAL(3,1); The Movie table has the following columns:
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 The YearStats table has the following columns: Year—integer TotalGross—bigint unsigned Releases—integer Write a SQL statement to designate the Year column in the Movie table as a foreign key to the Year column in the YearStats table. - correct answer ✔ALTER TABLE Movie ADD FOREIGN KEY (Year) REFERENCES YearStats(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—integer Write a SQL statement to create an index named idx_year on the Year column of the Movie table. - correct answer ✔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. - correct answer ✔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. - correct answer ✔DELETE FROM Movie WHERE ID = 3;
Write a SQL query to retrieve the Title and Genre values for all records in the Movie table with a Year value of 2020. Ensure your result set returns the columns in the order indicated. - correct answer ✔SELECT Title, Genre FROM Movie WHERE Year = 2020; 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 query to display all Title values in alphabetical order A-Z. - correct answer ✔SELECT Title FROM Movie ORDER BY Title ASC; 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 query to output the unique RatingCode values and the number of movies with each rating value from the Movie table as RatingCodeCount. Sort the results by the RatingCode in alphabetical order A-Z. Ensure your result set
returns the columns in the order indicated. - correct answer ✔SELECT RatingCode, COUNT(*) AS RatingCodeCount FROM Movie GROUP BY RatingCode ORDER BY RatingCode ASC; 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 The YearStats table has the following columns: Year—integer TotalGross—bigint unsigned Releases—integer Write a SQL query to display both the Title and the TotalGross (if available) for all movies. Ensure your result set returns the columns in the order indicated. - correct answer ✔SELECT Movie.Title, YearStats.TotalGross FROM Movie LEFT JOIN YearStats ON Movie.Year = YearStats.Year;