SQL CRUD Lab
Lab Objectives
- Practice using
SELECTUPDATEREMOVEandINSERT
Practice
In small groups, use PgAdmin to create, update, remove, and query some records for the Library database we created yesterday. There are some required activities below, but feel free to experiment with your database! If you ever feel that you need a fresh start for your database, reach out to your instructors.
Add Books to the Library and Create Library Patrons
- Use
INSERTto create at least 5 patrons for your library (these can be real, or fake people). - Use
INSERTto create at least 10 books in your library. You could have multiple copies of some books, but make sure you have at least 3 unique book titles, and 3 unique authors. (books can also be real, or fake)
When creating records, make sure each record has information in all the database columns!
Check Out Books
- Use
UPDATEto add a patron to at least 4 of your books (indicating that the book has been checked out by that patron). Make sure that at least 2 different patrons have checked out a book.
Remove Old Books
- Occasionally, libraries need to pull books out of circulation (perhaps someone wrote in the margins, or the book has too much wear and tear). Use
REMOVEto delete the 3 oldest books in the library (the three you created first).
Query for Available and Unavailable Books
- Use
SELECTandWHEREto return the title and author of all books that are not checked out. - Use
SELECTandWHEREto return the title and author of all books that are checked out. - For each patron, use
SELECTandWHEREto return the title of the books each patron has checked out.
Exit Ticket
Send a slack message to your instructors with the SELECT queries you created in the last section above.