

























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 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.
ANSWER CREATE TABLE Member ī ID INT PRIMARY KEY 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.
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.
ANSWER ALTER TABLE Movie 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.
ANSWER CREATE VIEW MyMovies AS SELECT Title, Genre, Year FROM Movie;
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.
ANSWER 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 delete the row with the ID value of 3 from the Movie table.
ANSWER DELETE FROM Movie WHERE ID ī 3;
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.
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 return how many movies have a Year value of 2019.
ANSWER SELECT COUNTī*ī AS MovieCount FROM Movie WHERE Year ī 2019;
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.
ANSWER SELECT Movie.Title, YearStats.TotalGross FROM Movie LEFT JOIN YearStats ON Movie.Year = YearStats.Year;
San Francisco, CA 94110 USA , How many attributes are present in the address fragment?
ANSWER 4 Attributes
The Package table has the following columns: Weightādecimal, Descriptionāoptional variable length string, LastChangedDateādate, TrackingNumberāinteger, Which column should be designated the primary key for the Package table?
ANSWER TrackingNumber
Which data type will store "2022ī 01 ī 10 14 ī 22 ī12" as a temporal value without loss of information?
ANSWER DATETIME
Define a UPDATE statement?
ANSWER UPDATE table_name SET column 1 ī value1, column 2 ī value2, ... WHERE condition;
Define a DELETE statement?
ANSWER DELETE FROM table_name WHERE condition;
The Book table has the following columns: genre - varchar(20), pages - integer, author_id - char(3), isbn_number - varchar(20), Which column should be designated at the primary key for the Book table?
ANSWER isbn_number
The Book table has the following columns: genre - varchar(20), pages - integer, author_id - char(3), isbn_number - varchar(20), Which column should be designated as the foreign key for the Book table?
ANSWER author_id
Which data type represents numbers with fractional values:
ANSWER DECIMAL
Which of the following is a DML command?
ANSWER INSERT, DELETE, UPDATE
CREATE TABLE Invoice ( invoice_id INT NOT NULL AUTO_INCREMENT, date DATE NOT NULL, customer_id INT NOT NULL, PRIMARY KEY (invoice_id), FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE CASCADE ); Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with foreign key reference statement above, what would happen to invoices in the Invoice table that are linked to a customer if that customer is deleted.
ANSWER Those invoices would be deleted also.
The Customer table will have the following columns: CustomerIDāpositive integer, FirstNameā variable-length string with up to 50 characters, MiddleInitialāfixed-length string with 1 character, LastNameāvariable-length string with up to 50 characters, DateOfBirthādate, CreditLimitāpositive decimal value representing a cost of up to $19,999, with 2 digits for cents, Write a SQL statement to create the Customer table. Do not add any additional constraints to any column beyond what is stated.
ANSWER CREATE TABLE Customer ī CustomerID INT UNSIGNED, FirstName VARCHARī 50 ī, MiddleInitial CHARī 1 ī, LastName VARCHARī 50 ī, DateOfBirth DATE, CreditLimit DECIMALī7,2ī UNSIGNED );
The Genre table has the following columns: GenreCodeāvariable-length string, primary key, GenreDescriptionāvariable-length string, The Book table should have the following columns: Titleāvariable-length string, maximum 30 characters, GenreCodeāvariable-length string, maximum 5 characters, Write a SQL statement to create the Book table. Designate the GenreCode column in the Book table as a foreign key to the GenreCode column in the Genre table.
ANSWER CREATE TABLE Book ( Title VARCHARī 30 ī, GenreCode VARCHARī 5 ī, FOREIGN KEY īGenreCode) REFERENCES Genre(GenreCode) );
The Automobile table has the following columns: IDāinteger, primary key, Makeāvariable-length string, Modelāvariable-length string, Yearāinteger, A new column must be added to the Automobile table: Column name: SafetyRating, Data type: decimal(3,1), Write a SQL statement to add the SafetyRating column to the Automobile table.
ANSWER ALTER TABLE Automobile ADD SafetyRating DECIMALī3,1ī;
The Book table has the following columns: IDāinteger, primary key, Titleāvariable-length string, Genreāvariable-length string, Yearāinteger, Write a SQL statement to create a view named My-Books that contains the Title, Genre, and Year columns for all movies books. Ensure your result set returns the columns in the order indicated.
ANSWER CREATE VIEW MyBooks AS SELECT Title, Genre, Year FROM Book;
A database has a view named BookView. Write a SQL statement to delete the view named BookView from the database.
ANSWER DROP VIEW BookView;
The Book table has the following columns: IDāinteger, primary key, auto_increment Titleāvariable- length string, Genreāvariable-length string, Yearāinteger, The following data needs to be added to the Book table: Title Genre Year, The Joy Luck Club, Fiction, 1989, Write a SQL statement to insert the indicated data into the Book table.
ANSWER INSERT INTO Book īTitle, Genre, Year) VALUES ('The Joy Luck Club', 'Fiction', 1989 ī;
The Book table has the following columns: IDāinteger, primary key, auto_increment, Titleāvariable- length string, Genreāvariable-length string, Yearāinteger , Write a SQL statement to delete the row with the ID value of 3 from the Book table.
ANSWER DELETE from Book WHERE ID ī 3;
The Book table has the following columns: IDāinteger, primary key, auto_increment, Titleāvariable- length string, Genreāvariable-length string, Yearāinteger, Write a SQL statement to update the Year value to be 2022 for all books with a Year value of 2020.
ANSWER UPDATE Book SET Year ī 2022 WHERE Year ī 2020;
Which query illustrates performing an outer join of the Book table with a different table?
ANSWER SELECT Book.Title, A.Author FROM Book B RIGHT JOIN Author A ON B.AuthorID ī A.ID
Assume there are two tables, A and B. Which rows will always be included in the result set if Table A is inner joined with Table B?
ANSWER Only rows in Tables A and B that share the join condition
The database contains a table named Book. Write a SQL query to return all data from the Book table without directly referencing any column names.
ANSWER SELECT * FROM Book;
The Book table has the following columns: IDāinteger, primary key, auto_increment, Titleāvariable- length string, Genreāvariable-length string, Yearāinteger, Write a SQL query to retrieve the Title and Genre values for all records in the Book table with a Year value of 2020. Ensure your result set returns the columns in the order indicated.
ANSWER SELECT Title, Genre FROM Book WHERE Year ī 2020;
The Book table has the following columns: IDāinteger, primary key, auto_increment, Titleāvariable- length string, Genreāvariable-length string, Yearāinteger, Write a SQL query to return how many books have a Year value of 2019.
ANSWER SELECT COUNTī*ī FROM Book WHERE Year ī 2019;
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 SELECT statement to select the year and the total number of movies for that year. Hint: Use the COUNTīī function and GROUP BY clause.
ANSWER SELECT Year, COUNTī*ī AS TotalMovies FROM Movie GROUP 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 - integer, The Rating table has the following columns: Code - variable-length string, primary key, Description - variable-length string, Write a SELECT statement to select the Title, Year, and rating Description. Display all movies, whether or not a RatingCode is available. Hint: Perform a LEFT JOIN on the Movie and Rating tables, matching the RatingCode and Code columns.
ANSWER SELECT Movie.Title, Movie.Year, Rating.Description FROM Movie LEFT JOIN Rating ON Movie.RatingCode ī Rating.Code;
The Employee table has the following columns: ID ī integer, primary key, FirstName - variable-length string, LastName - variable-length string, ManagerID ī integer, Write a SELECT statement to show a list of all employees' first names and their managers' first names. List only employees that have a manager. Order the results by Employee first name. Use aliases to give the result columns distinctly different names, like "Employee" and "Manager". Hint: Join the Employee table to itself using INNER JOIN.
ANSWER SELECT E.FirstName AS Employee, M.FirstName AS Manager FROM Employee E JOIN Employee M ON E.ManagerID ī M.ID ORDER BY E.FirstName;
The database has three tables for tracking horse-riding lessons:
Horse with columns: ID ī primary key, RegisteredName, Breed, Height, BirthDate,
HorseID ī partial primary key, foreign key references Horse(ID), StudentID ī foreign key references Student(ID), LessonDateTime - partial primary key,
Write a SELECT statement to create a lesson schedule for Feb 1, 2020 with the lesson date/time, student's first and last names, and the horse's registered name. Order the results in ascending order by lesson date/time, then by the horse's registered name. Make sure unassigned lesson times (student ID is NULLī appear in the results. Hint: Perform a join on the LessonSchedule, Student, and Horse tables, matching the student IDs and horse IDs.
ANSWER SELECT LS.LessonDateTime, S.FirstName, S.Last-Name, H.RegisteredName FROM LessonSchedule LS LEFT JOIN Student S ON LS.StudentID ī S.ID LEFT JOIN Horse H ON LS.HorseID ī H.ID WHERE LS.LessonDateTime >= '2020ī 02 ī01' AND LS.LessonDateTime < '2020ī 02 ī02' ORDER BY LS.LessonDateTime ASC, H.RegisteredName ASC;
The Horse table has the following columns: 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 and height for only horses that have an above average height. Order the results by height (ascending). Hint: Use a subquery to find the average height.
ANSWER SELECT RegisteredName, Height From Horse Where Height > ( SELECT AVGīHeight) From Horse ) Order By Height ASC;
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.
ANSWER ALTER Table Movie ADD Producer Varchar(50), Drop 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.0, 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 ī10, Independence, Holsteiner, 16.0, 2017 ī 03 ī13, Ellie, Saddlebred, 15.0, 2016 ī 12 ī22, NULL, Egyptian Arab, 14.9, 2019 ī 10 ī 12,
ANSWER 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');