SQL-101-Basics
  • Introduction
  • Part 1: Transact-SQL
    • 1.0: Getting Started with T-SQL
    • 1.1: Create Database
    • 1.2: Drop Database
    • 1.3: Create Table
    • 1.4: Insert
    • 1.5: Update
    • 1.6: Read
    • 1.7: Alter
    • 1.8: Customer Table
    • 1.9: Diagramming Notation
    • 1.10: Foreign Keys
    • 1.11: Join
    • 1.12: Solutions
  • Part 2: PostgreSQL
    • 2.0: Getting Started with PostgreSQL
    • 2.1: Create Database
    • 2.2: Drop Database
    • 2.3: Create Table
    • 2.4: Insert
    • 2.5: Update
    • 2.6: Read
    • 2.7: Alter
    • 2.8: Customer Table
    • 2.9: Diagramming Notation
    • 2.10: Foreign Keys
    • 2.11: Join
    • 2.12: Solutions
  • Part 3: T-SQL Challenges
    • 3.0: Introduction
    • 3.1: Challenge 1
    • 3.2: Challenge 2
    • 3.3: Challenge 3
    • 3.4: Challenge 4
    • 3.5: Solutions
  • Part 4: PostgreSQL Challenges
    • 4.0: Introduction
    • 4.1: Challenge 1
    • 4.2: Challenge 2
    • 4.3: Challenge 3
    • 4.4: Challenge 4
    • 4.5: Solutions
  • Part 5: Resources
    • 5.0: Resources
Powered by GitBook
On this page
  1. Part 4: PostgreSQL Challenges

4.2: Challenge 2

Previous4.1: Challenge 1Next4.3: Challenge 3

Last updated 7 years ago

Now, write a query that generates 3 tables (Library, Member, and Book) with these specifications:

  • The Library table should include the following properties: LibraryId and LocationName.

  • The Member table should include the following properties: MemberId, FirstName, and LastName.

  • The Book table should include the following properties: BookId, Title, Author, CheckOutDate, and DueDate.

You will also need to link the tables with foreign keys to demonstrate these relationships:

  • A member can have many books; a book can have 0 or 1 members.

  • A library can have many books; a book can have only 1 library.

  • A library can have many members; a member can have only 1 library.

For extra practice, map out the table entities using UML notation.

Click to see the solution for this challenge. Then, continue to for the next challenge.

Part 4.3
here