Skip to content

Edward Gonzalez#72

Open
eddygonzalez9708 wants to merge 4 commits intobloominstituteoftechnology:masterfrom
eddygonzalez9708:master
Open

Edward Gonzalez#72
eddygonzalez9708 wants to merge 4 commits intobloominstituteoftechnology:masterfrom
eddygonzalez9708:master

Conversation

@eddygonzalez9708
Copy link

@eddygonzalez9708 eddygonzalez9708 commented Sep 4, 2018

Exercises, Day 1

  1. Create a table called track that holds information about a music track. It should contain:
  • An autoincrementing id
  • A title (of type VARCHAR, probably)
  • A reference to an id in table album (the album the track is on). This should be a foreign key.
  1. Create a table called artist_album to connect artists to albums. (Note that an artist might have several albums and an album might be created by multiple artists.)
  • Use foreign keys for this, as well.
  1. Run the queries in the file setup.sql. This will populate the tables.
  • Fix any errors at this point by making sure your tables are correct.
  • DROP TABLE can be used to delete a table so you can recreate it with CREATE TABLE.
  1. Write SQL SELECT queries that:
  • Show all albums.
  • Show all albums made between 1975 and 1990.
  • Show all albums whose names start with Super D.
  • Show all albums that have no release year.
  1. Write SQL SELECT queries that:
  • Show all track titles from Super Funky Album.
  • Same query as above, but rename the column from title to Track_Title in the output.
  • Select all album titles by Han Solo.
  • Select the average year all albums were released.
  • Select the average year all albums by Leia and the Ewoks were released.
  • Select the number of artists.
  • Select the number of tracks on Super Dubstep Album.

Exercises, Day 2

  1. Create a database for taking notes.
  • What are the columns that a note table needs?
  • If you have a timestamp field, how do you auto-populate it with the date?
  • A note should have a foreign key pointing to an author in an author table.
  • What columns are needed for the author table?
  1. Write queries that:
  • Insert authors to the author table.

  • Insert notes to the note table.

  • Select all notes by an author's name.

  • Select author for a particular note by note ID.

  • Select the names of all the authors along with the number of notes they each have. (Hint: GROUP BY.)

  • Delete authors from the author table.(Note that SQLite doesn't enforce foreign key constrains by default. You have to enable them by running PRAGMA foreign_keys = ON; before your queries.)

  • What happens when you try to delete an author with an existing note?

  • How can you prevent this?

  • Submit a file notes.sql with the queries that build (CREATE TABLE/INSERT) and query the database as noted above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant