diff --git a/Chapter_07/Chapter_07.sql b/Chapter_07/Chapter_07.sql index b47624b..d5a3a87 100644 --- a/Chapter_07/Chapter_07.sql +++ b/Chapter_07/Chapter_07.sql @@ -133,6 +133,7 @@ FROM district_2020 LEFT JOIN district_2035 ON district_2020.id = district_2035.id WHERE district_2035.id IS NULL; +-- alternately, with a RIGHT JOIN SELECT * FROM district_2020 RIGHT JOIN district_2035 ON district_2020.id = district_2035.id diff --git a/Chapter_08/Chapter_08.sql b/Chapter_08/Chapter_08.sql index bdc07a2..06f0c5f 100644 --- a/Chapter_08/Chapter_08.sql +++ b/Chapter_08/Chapter_08.sql @@ -155,6 +155,10 @@ CREATE TABLE not_null_example ( CONSTRAINT student_id_key PRIMARY KEY (student_id) ); +-- This will fail: +INSERT INTO not_null_example (first_name, last_name) +VALUES ('Sting', NULL); + -- Listing 8-11: Dropping and adding a primary key and a NOT NULL constraint -- Drop diff --git a/Try_It_Yourself/Try_It_Yourself.sql b/Try_It_Yourself/Try_It_Yourself.sql index 044ed7b..a18399e 100644 --- a/Try_It_Yourself/Try_It_Yourself.sql +++ b/Try_It_Yourself/Try_It_Yourself.sql @@ -306,7 +306,7 @@ GROUP BY state_name; -- 1. According to the census population estimates, which county had the -- greatest percentage loss of population between 2010 and 2019? Try --- an internet search to find out what happened. (Hint: The loss is related +-- an internet search to find out what happened. (Hint: The decrease is related -- to a particular type of facility.) -- Answer: @@ -378,28 +378,28 @@ ON c2019.state_fips = c2010.state_fips -- track of your vinyl LP collection. Start by reviewing these CREATE TABLE -- statements. --- The albums table includes information specific to the overall collection --- of songs on the disc. The songs table catalogs each track on the album. --- Each song has a title and a column for its composers, who might be --- different than the album artist. - CREATE TABLE albums ( - album_id bigserial, - catalog_code varchar(100), + album_id bigint GENERATED ALWAYS AS IDENTITY, + catalog_code text, title text, artist text, release_date date, - genre varchar(40), + genre text, description text ); CREATE TABLE songs ( - song_id bigserial, + song_id bigint GENERATED ALWAYS AS IDENTITY, title text, composers text, album_id bigint ); +-- The albums table includes information specific to the overall collection +-- of songs on the disc. The songs table catalogs each track on the album. +-- Each song has a title and a column for its composers, who might be +-- different than the album artist. + -- Use the tables to answer these questions: -- 1. Modify these CREATE TABLE statements to include primary and foreign keys