ANSWER KEY 2024.
1.47 Write the SQL to create a Product table with the following columns:
ID - Integer
Name - Variable-length string with maximum 40 characters
ProductType - Variable-length string with maximum 3 characters
OriginDate - Year, month, and day
Weight - Decimal number with six significant digits and one digit after the -
decimal point
Place your CREATE TABLE statement before the INSERT and SELECT
statements. Run your solution and verify the result table contains the three
inserted rows.
CREATE TABLE Product (
ID INT,
Name VARCHAR(40),
ProductType VARCHAR(3),
OriginDate DATE,
Weight DECIMAL(6,1)
);
1.54 Write the SQL to create a Product table with the following columns:
ID - Integer with range 0 to 65,535
Name - Variable-length string with maximum 40 characters
ProductType - Fixed-length string with 3 characters
OriginDateTime - Year, month, day, and time
Weight - Decimal number with variable precision and 4 bytes of storage
Place your CREATE TABLE statement before the INSERT and SELECT
,statements. Run your solution and verify the result table contains the three
inserted rows.
CREATE TABLE Product (
ID SMALLINT UNSIGNED,
Name VARCHAR(40),
ProductType CHAR(3),
OriginDateTime DATETIME,
Weight FLOAT
);
1.6.9
The given SQL creates a Movie table and inserts some movies. The SELECT
statement selects all movies released before January 1, 2000.
Modify the SELECT statement to select the title and release date of PG-13 movies
that are released after January 1, 2008.
Run your solution and verify the result table shows just the titles and release
dates for The Dark Knight and Crazy Rich Asians.
SELECT Title, ReleaseDate
FROM Movie
WHERE Rating = 'PG-13' AND ReleaseDate > '2008-01-01';
1.79
Modify the SELECT statement to only select songs that have a NULL Title value.
Then run your solution, and verify the new query returns only songs by Taylor
Swift and Nirvana.
SELECT *
FROM Song
WHERE Title IS NULL;
1.7.11
Modify the SELECT statement to select only songs that have a NULL Title or
NULL Artist.
, SELECT * FROM Song WHERE Title IS NULL OR Artist IS NULL;
or
SELECT * FROM Song WHERE Title = NULL OR Artist = NULL;
1.8.6
Write three UPDATE statements to make the following changes:
Change the title from 'One' to 'With Or Without You'.
Change the artist from 'The Righteous Brothers' to 'Aretha Franklin'.
Change the release years of all songs after 1990 to 2021.
UPDATE Song
SET Title = 'With Or Without You'
WHERE ID = 200;
UPDATE Song
SET Artist = 'Aretha Franklin'
WHERE ID = 300;
UPDATE Song
SET ReleaseYear = 2021
WHERE ReleaseYear > 1990;
197
The given SQL creates a Movie table with an auto-incrementing ID column.
Write a single INSERT statement immediately after the CREATE TABLE statement
that inserts the following movies:
Raiders of the Lost Ark PG June 15, 1981
The Godfather R March 24, 1972
The Pursuit of Happyness PG-13 December 15, 2006
INSERT INTO Movie (Title, Rating, ReleaseDate)
VALUES ('Raiders of the Lost Ark', 'PG', '1981-06-15'),
('The Godfather', 'R', '1972-03-24'),
('The Pursuit of Happyness', 'PG-13', '2006-12-15');