diff --git a/Chapter_04/Chapter_04.sql b/Chapter_04/Chapter_04.sql index 99251a6..9b2502a 100644 --- a/Chapter_04/Chapter_04.sql +++ b/Chapter_04/Chapter_04.sql @@ -9,7 +9,7 @@ CREATE TABLE char_data_types ( char_column char(10), - varchar_column varchar(10), + varchar_column varchar(10), text_column text ); diff --git a/Chapter_05/Chapter_05.sql b/Chapter_05/Chapter_05.sql index 50c96c2..3a7d8aa 100644 --- a/Chapter_05/Chapter_05.sql +++ b/Chapter_05/Chapter_05.sql @@ -22,21 +22,21 @@ CREATE TABLE us_counties_pop_est_2019 ( state_fips text, -- State FIPS code county_fips text, -- County FIPS code region smallint, -- Region - state_name text, -- State name - county_name text, -- County name + state_name text, -- State name + county_name text, -- County name area_land bigint, -- Area (Land) in square meters area_water bigint, -- Area (Water) in square meters internal_point_lat numeric(10,7), -- Internal point (latitude) internal_point_lon numeric(10,7), -- Internal point (longitude) - pop_est_2018 integer, -- 2018-07-01 resident total population estimate - pop_est_2019 integer, -- 2019-07-01 resident total population estimate - births_2019 integer, -- Births from 2018-07-01 to 2019-06-30 - deaths_2019 integer, -- Deaths from 2018-07-01 to 2019-06-30 - international_migr_2019 integer, -- Net international migration from 2018-07-01 to 2019-06-30 - domestic_migr_2019 integer, -- Net domestic migration from 2018-07-01 to 2019-06-30 - residual_2019 integer, -- Residual for 2018-07-01 to 2019-06-30 - CONSTRAINT counties_2019_key PRIMARY KEY (state_fips, county_fips) -); + pop_est_2018 integer, -- 2018-07-01 resident total population estimate + pop_est_2019 integer, -- 2019-07-01 resident total population estimate + births_2019 integer, -- Births from 2018-07-01 to 2019-06-30 + deaths_2019 integer, -- Deaths from 2018-07-01 to 2019-06-30 + international_migr_2019 integer, -- Net international migration from 2018-07-01 to 2019-06-30 + domestic_migr_2019 integer, -- Net domestic migration from 2018-07-01 to 2019-06-30 + residual_2019 integer, -- Residual for 2018-07-01 to 2019-06-30 + CONSTRAINT counties_2019_key PRIMARY KEY (state_fips, county_fips) +); SELECT * FROM us_counties_pop_est_2019; @@ -46,8 +46,7 @@ SELECT * FROM us_counties_pop_est_2019; -- Windows users: Please check the Note on PAGE XXXXXX as well. COPY us_counties_pop_est_2019 --- FROM 'C:\YourDirectory\us_counties_2010.csv' -FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_pop_est_2019.csv' +FROM 'C:\YourDirectory\us_counties_pop_est_2019.csv' WITH (FORMAT CSV, HEADER); -- Checking the data @@ -69,7 +68,7 @@ LIMIT 5; CREATE TABLE supervisor_salaries ( id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - town text, + town text, county text, supervisor text, start_date text, @@ -80,8 +79,7 @@ CREATE TABLE supervisor_salaries ( -- Listing 5-5: Importing salaries data from CSV to three table columns COPY supervisor_salaries (town, supervisor, salary) --- FROM 'C:\YourDirectory\supervisor_salaries.csv' -FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/supervisor_salaries.csv' +FROM 'C:\YourDirectory\supervisor_salaries.csv' WITH (FORMAT CSV, HEADER); -- Check the data @@ -96,8 +94,7 @@ CREATE TEMPORARY TABLE supervisor_salaries_temp (LIKE supervisor_salaries INCLUDING ALL); COPY supervisor_salaries_temp (town, supervisor, salary) --- FROM 'C:\YourDirectory\supervisor_salaries.csv' -FROM '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/supervisor_salaries.csv' +FROM 'C:\YourDirectory\supervisor_salaries.csv' WITH (FORMAT CSV, HEADER); INSERT INTO supervisor_salaries (town, county, supervisor, salary) @@ -113,8 +110,7 @@ SELECT * FROM supervisor_salaries LIMIT 2; -- Listing 5-7: Export an entire table with COPY COPY us_counties_pop_est_2019 --- TO 'C:\YourDirectory\us_counties_export.txt' -TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_export.txt' +TO 'C:\YourDirectory\us_counties_export.txt' WITH (FORMAT CSV, HEADER, DELIMITER '|'); @@ -122,8 +118,7 @@ WITH (FORMAT CSV, HEADER, DELIMITER '|'); COPY us_counties_pop_est_2019 (county_name, internal_point_lat, internal_point_lon) --- TO 'C:\YourDirectory\us_counties_latlon_export.txt' -TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_latlon_export.csv' +TO 'C:\YourDirectory\us_counties_latlon_export.txt' WITH (FORMAT CSV, HEADER, DELIMITER '|'); -- Listing 5-9: Exporting query results with COPY @@ -133,6 +128,5 @@ COPY ( FROM us_counties_pop_est_2019 WHERE county_name ILIKE '%mill%' ) --- TO 'C:\YourDirectory\us_counties_mill_export.csv' -TO '/Users/DeBarrosA/Dropbox (Personal)/DataMonky/Book-Writing/PracticalSQL_2e/Code-Repo/Chapter_05/us_counties_mill_export.csv' +TO 'C:\YourDirectory\us_counties_mill_export.csv' WITH (FORMAT CSV, HEADER);