diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/SQL.BuildAndDestroy.iml b/.idea/SQL.BuildAndDestroy.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/SQL.BuildAndDestroy.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9bfba77 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/answers/exercise1.sql b/answers/exercise1.sql index e69de29..29dc357 100644 --- a/answers/exercise1.sql +++ b/answers/exercise1.sql @@ -0,0 +1 @@ +mysql> CREATE DATABASE myNewDB \ No newline at end of file diff --git a/answers/exercise10.sql b/answers/exercise10.sql index e69de29..8e02f62 100644 --- a/answers/exercise10.sql +++ b/answers/exercise10.sql @@ -0,0 +1 @@ +mysql> SELECT * FROM Students WHERE City='Philadelphia' OR City='Trenton'; \ No newline at end of file diff --git a/answers/exercise11.sql b/answers/exercise11.sql index e69de29..2bb12ee 100644 --- a/answers/exercise11.sql +++ b/answers/exercise11.sql @@ -0,0 +1,9 @@ +mysql> SELECT * FROM Students ORDER BY City ASC; ++-------------+-------------+--------------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++-------------+-------------+--------------+----------+------------+ +| Jane Doe | 57 Union St | Glasgow | Scotland | G13RB | +| John Doe | 58 Union St | Philadelphia | USA | 19805 | +| Joe Doe | 58 Union St | Trenton | USA | 19805 | +| John John | 58 Union St | Wilmington | USA | 19805 | ++-------------+-------------+--------------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise12.sql b/answers/exercise12.sql index e69de29..8f277a7 100644 --- a/answers/exercise12.sql +++ b/answers/exercise12.sql @@ -0,0 +1,9 @@ +mysql> SELECT * FROM Students ORDER BY City DESC; ++-------------+-------------+--------------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++-------------+-------------+--------------+----------+------------+ +| John John | 58 Union St | Wilmington | USA | 19805 | +| Joe Doe | 58 Union St | Trenton | USA | 19805 | +| John Doe | 58 Union St | Philadelphia | USA | 19805 | +| Jane Doe | 57 Union St | Glasgow | Scotland | G13RB | ++-------------+-------------+--------------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise13.sql b/answers/exercise13.sql index e69de29..d0034e2 100644 --- a/answers/exercise13.sql +++ b/answers/exercise13.sql @@ -0,0 +1,11 @@ +mysql> SELECT * FROM Students ORDER BY Country ASC, City ASC; ++-------------+-------------+--------------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++-------------+-------------+--------------+----------+------------+ +| Jose Jose | 58 Union St | ACityName | Mexico | 19805 | +| Jose Jose | 58 Union St | Wilmington | Mexico | 19805 | +| Jane Doe | 57 Union St | Glasgow | Scotland | G13RB | +| John Doe | 58 Union St | Philadelphia | USA | 19805 | +| Joe Doe | 58 Union St | Trenton | USA | 19805 | +| John John | 58 Union St | Wilmington | USA | 19805 | ++-------------+-------------+--------------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise14.sql b/answers/exercise14.sql index e69de29..dd34f0f 100644 --- a/answers/exercise14.sql +++ b/answers/exercise14.sql @@ -0,0 +1,16 @@ + + +/*Should I have created the table without + including IS NOT NULL? + That way my query would have said + 'WHERE PostalCode IS NULL;' + */ + + +mysql> SELECT * FROM Students WHERE PostalCode=''; ++---------------+-------------+-----------+---------+------------+ +| StudentName | Address | City | Country | PostalCode | ++---------------+-------------+-----------+---------+------------+ +| Jose Jose | 58 Union St | ACityName | Mexico | | +| Jose LastName | 58 Union St | ACityName | Mexico | | ++---------------+-------------+-----------+---------+------------+ \ No newline at end of file diff --git a/answers/exercise15.sql b/answers/exercise15.sql index e69de29..7326653 100644 --- a/answers/exercise15.sql +++ b/answers/exercise15.sql @@ -0,0 +1,13 @@ +mysql> SELECT * FROM Students WHERE PostalCode IS NOT NULL; ++---------------+-------------+--------------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++---------------+-------------+--------------+----------+------------+ +| Jane Doe | 57 Union St | Glasgow | Scotland | G13RB | +| John Doe | 58 Union St | Philadelphia | USA | 19805 | +| Joe Doe | 58 Union St | Trenton | USA | 19805 | +| John John | 58 Union St | Wilmington | USA | 19805 | +| Jose Jose | 58 Union St | Wilmington | Mexico | 19805 | +| Jose Jose | 58 Union St | ACityName | Mexico | 19805 | +| Jose Jose | 58 Union St | ACityName | Mexico | | +| Jose LastName | 58 Union St | ACityName | Mexico | | ++---------------+-------------+--------------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise16.sql b/answers/exercise16.sql index e69de29..3ad8aed 100644 --- a/answers/exercise16.sql +++ b/answers/exercise16.sql @@ -0,0 +1,15 @@ +/*From The Last Kingdom?*/ + +mysql> UPDATE Students SET City = 'Edinburgh'; ++---------------+-------------+-----------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++---------------+-------------+-----------+----------+------------+ +| Jane Doe | 57 Union St | Edinburgh | Scotland | G13RB | +| John Doe | 58 Union St | Edinburgh | USA | 19805 | +| Joe Doe | 58 Union St | Edinburgh | USA | 19805 | +| John John | 58 Union St | Edinburgh | USA | 19805 | +| Jose Jose | 58 Union St | Edinburgh | Mexico | 19805 | +| Jose Jose | 58 Union St | Edinburgh | Mexico | 19805 | +| Jose Jose | 58 Union St | Edinburgh | Mexico | | +| Jose LastName | 58 Union St | Edinburgh | Mexico | | ++---------------+-------------+-----------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise17.sql b/answers/exercise17.sql index e69de29..f69564f 100644 --- a/answers/exercise17.sql +++ b/answers/exercise17.sql @@ -0,0 +1,13 @@ +mysql> UPDATE Students SET City = 'Edinburgh' WHERE Country = 'Scotland'; ++---------------+-------------+-----------+----------+------------+ +| StudentName | Address | City | Country | PostalCode | ++---------------+-------------+-----------+----------+------------+ +| Jane Doe | 57 Union St | Edinburgh | Scotland | G13RB | +| John Doe | 58 Union St | CityName | USA | 19805 | +| Joe Doe | 58 Union St | CityName | USA | 19805 | +| John John | 58 Union St | CityName | USA | 19805 | +| Jose Jose | 58 Union St | CityName | Mexico | 19805 | +| Jose Jose | 58 Union St | CityName | Mexico | 19805 | +| Jose Jose | 58 Union St | CityName | Mexico | | +| Jose LastName | 58 Union St | CityName | Mexico | | ++---------------+-------------+-----------+----------+------------+ \ No newline at end of file diff --git a/answers/exercise18.sql b/answers/exercise18.sql index e69de29..9152ef0 100644 --- a/answers/exercise18.sql +++ b/answers/exercise18.sql @@ -0,0 +1 @@ +UPDATE Students SET City='EdinBurgh', Country='Scotland' Where ID='35'; \ No newline at end of file diff --git a/answers/exercise19.sql b/answers/exercise19.sql index e69de29..2cdd0fd 100644 --- a/answers/exercise19.sql +++ b/answers/exercise19.sql @@ -0,0 +1 @@ +DELETE FROM Students WHERE Country = 'Scotland'; \ No newline at end of file diff --git a/answers/exercise2.sql b/answers/exercise2.sql index e69de29..94cc5a9 100644 --- a/answers/exercise2.sql +++ b/answers/exercise2.sql @@ -0,0 +1 @@ +mysql> DROP DATABASE myNewDB; \ No newline at end of file diff --git a/answers/exercise20.sql b/answers/exercise20.sql index e69de29..6f76379 100644 --- a/answers/exercise20.sql +++ b/answers/exercise20.sql @@ -0,0 +1 @@ +TRUNCATE TABLE Students; \ No newline at end of file diff --git a/answers/exercise3.sql b/answers/exercise3.sql index e69de29..2ff78ae 100644 --- a/answers/exercise3.sql +++ b/answers/exercise3.sql @@ -0,0 +1,6 @@ +mysql> CREATE TABLE Users ( + -> UserID INTEGER KEY NOT NULL AUTO_INCREMENT, + -> LastName VARCHAR(255) NOT NULL, + -> FirstName VARCHAR(255) NOT NULL, + -> Address VARCHAR(255) NOT NULL, + -> City VARCHAR(255) NOT NULL); \ No newline at end of file diff --git a/answers/exercise4.sql b/answers/exercise4.sql index e69de29..e5dacc4 100644 --- a/answers/exercise4.sql +++ b/answers/exercise4.sql @@ -0,0 +1,3 @@ +DROP TABLE Users; + + diff --git a/answers/exercise5.sql b/answers/exercise5.sql index e69de29..12321ad 100644 --- a/answers/exercise5.sql +++ b/answers/exercise5.sql @@ -0,0 +1 @@ +TRUNCATE TABLE Users; \ No newline at end of file diff --git a/answers/exercise6.sql b/answers/exercise6.sql index e69de29..ccde2fd 100644 --- a/answers/exercise6.sql +++ b/answers/exercise6.sql @@ -0,0 +1 @@ +mysql> ALTER TABLE Users ADD COLUMN Birthday DATE; \ No newline at end of file diff --git a/answers/exercise7.sql b/answers/exercise7.sql index e69de29..550ea79 100644 --- a/answers/exercise7.sql +++ b/answers/exercise7.sql @@ -0,0 +1 @@ +ALTER TABLE Users DROP COLUMN Birthday; \ No newline at end of file diff --git a/answers/exercise8.sql b/answers/exercise8.sql index e69de29..ff433c3 100644 --- a/answers/exercise8.sql +++ b/answers/exercise8.sql @@ -0,0 +1 @@ +mysql> INSERT INTO Students (StudentName,Address,City,Country,PostalCode) VALUES ('Jane Doe','57 Union St','Glasgow','Scotland','G13RB'); \ No newline at end of file diff --git a/answers/exercise9.sql b/answers/exercise9.sql index e69de29..8a115c2 100644 --- a/answers/exercise9.sql +++ b/answers/exercise9.sql @@ -0,0 +1 @@ +mysql> SELECT * FROM Students WHERE City<>'Philadelphia'; \ No newline at end of file