Databases | Tasks for Practical Class 2
Using pgAdmin 4 ERD Tool
Task:
- Using pgAdmin 4 ERD Tool, create a new ERD project.
- Create the tables as defined in the schema, specifying appropriate data types and primary keys.
- Establish the relationships between the tables by creating foreign keys as indicated. Use the “one-to-many” relationship tool for each foreign key constraint.
- Auto-align the tables for better readability.
- Generate the SQL DDL script for this database schema.
- Save your ERD project.
Variant 1: Library Management System
Scenario: Design a database for a small library to manage its collection of books, authors, borrowers, and loans.
Database Schema:
- Tables:
Books:book_id(integer, Primary Key) - Unique identifier for each book.title(character varying) - Title of the book.isbn(character varying) - International Standard Book Number.publication_year(integer) - Year of publication.genre(character varying) - Genre of the book.
Authors:author_id(integer, Primary Key) - Unique identifier for each author.first_name(character varying) - Author’s first name.last_name(character varying) - Author’s last name.
Book_Authors: (Intersection table for many-to-many relationship between Books and Authors)book_id(integer, Foreign Key referencingBooks(book_id))author_id(integer, Foreign Key referencingAuthors(author_id))- (Composite Primary Key:
book_id,author_id)
Borrowers:borrower_id(integer, Primary Key) - Unique identifier for each borrower.first_name(character varying) - Borrower’s first name.last_name(character varying) - Borrower’s last name.address(character varying) - Borrower’s address.phone_number(character varying) - Borrower’s phone number.
Loans:loan_id(integer, Primary Key) - Unique identifier for each loan.book_id(integer, Foreign Key referencingBooks(book_id))borrower_id(integer, Foreign Key referencingBorrowers(borrower_id))loan_date(date) - Date when the book was borrowed.return_date(date, Nullable) - Date when the book was returned (can be null if not yet returned).
- Relationships:
- One-to-many relationship between
AuthorsandBook_Authors(One Author can write multiple books). - One-to-many relationship between
BooksandBook_Authors(One Book can be written by multiple authors). - One-to-many relationship between
BooksandLoans(One Book can be loaned multiple times). - One-to-many relationship between
BorrowersandLoans(One Borrower can take out multiple loans).
- One-to-many relationship between
Variant 2: Online Bookstore Database
Scenario: Design a database for an online bookstore to manage books, authors, customers, orders, and publishers.
Database Schema:
- Tables:
Books:book_id(integer, Primary Key)title(character varying)isbn(character varying)publication_year(integer)price(numeric)publisher_id(integer, Foreign Key referencingPublishers(publisher_id))
Authors:author_id(integer, Primary Key)first_name(character varying)last_name(character varying)
Book_Authors: (Intersection table)book_id(integer, Foreign Key referencingBooks(book_id))author_id(integer, Foreign Key referencingAuthors(author_id))- (Composite Primary Key:
book_id,author_id)
Customers:customer_id(integer, Primary Key)first_name(character varying)last_name(character varying)email(character varying)address(character varying)
Publishers:publisher_id(integer, Primary Key)publisher_name(character varying)publisher_address(character varying)
Orders:order_id(integer, Primary Key)customer_id(integer, Foreign Key referencingCustomers(customer_id))order_date(date)
Order_Items: (Intersection table for many-to-many relationship between Orders and Books)order_item_id(integer, Primary Key) - Unique identifier for each item in an order.order_id(integer, Foreign Key referencingOrders(order_id))book_id(integer, Foreign Key referencingBooks(book_id))quantity(integer)price(numeric) - Price of the book at the time of order (could be different from current book price).
- Relationships:
- One-to-many relationship between
AuthorsandBook_Authors. - One-to-many relationship between
BooksandBook_Authors. - One-to-many relationship between
PublishersandBooks. - One-to-many relationship between
CustomersandOrders. - One-to-many relationship between
OrdersandOrder_Items. - One-to-many relationship between
BooksandOrder_Items.
- One-to-many relationship between
Variant 3: University Course Enrollment System Database
Scenario: Design a database for a university to manage students, courses, professors, departments, and course enrollments.
Database Schema:
- Tables:
Students:student_id(integer, Primary Key)first_name(character varying)last_name(character varying)major(character varying)
Courses:course_id(integer, Primary Key)course_name(character varying)course_code(character varying)credits(integer)department_id(integer, Foreign Key referencingDepartments(department_id))
Professors:professor_id(integer, Primary Key)first_name(character varying)last_name(character varying)department_id(integer, Foreign Key referencingDepartments(department_id))
Departments:department_id(integer, Primary Key)department_name(character varying)building(character varying)
Enrollments: (Intersection table - represents a student enrolled in a course taught by a professor)enrollment_id(integer, Primary Key) - Unique identifier for each enrollment record.student_id(integer, Foreign Key referencingStudents(student_id))course_id(integer, Foreign Key referencingCourses(course_id))professor_id(integer, Foreign Key referencingProfessors(professor_id))semester(character varying) - e.g., “Fall 2024”, “Spring 2025”.grade(character varying, Nullable) - Grade received by the student (can be null if course is in progress).
- Relationships:
- One-to-many relationship between
DepartmentsandCourses. - One-to-many relationship between
DepartmentsandProfessors. - One-to-many relationship between
StudentsandEnrollments. - One-to-many relationship between
CoursesandEnrollments. - One-to-many relationship between
ProfessorsandEnrollments.
- One-to-many relationship between
Variant 4: Music Streaming Service Database
Scenario: Design a database for a music streaming service to manage artists, albums, songs, users, and playlists.
Database Schema:
- Tables:
Artists:artist_id(integer, Primary Key)artist_name(character varying)genre(character varying)
Albums:album_id(integer, Primary Key)album_name(character varying)artist_id(integer, Foreign Key referencingArtists(artist_id))release_year(integer)
Songs:song_id(integer, Primary Key)song_name(character varying)album_id(integer, Foreign Key referencingAlbums(album_id))track_number(integer)duration(integer) - Duration in seconds.
Users:user_id(integer, Primary Key)username(character varying, unique)email(character varying, unique)registration_date(date)
Playlists:playlist_id(integer, Primary Key)playlist_name(character varying)user_id(integer, Foreign Key referencingUsers(user_id))creation_date(date)
Playlist_Songs: (Intersection table)playlist_id(integer, Foreign Key referencingPlaylists(playlist_id))song_id(integer, Foreign Key referencingSongs(song_id))- (Composite Primary Key:
playlist_id,song_id) added_date(timestamp)
- Relationships:
- One-to-many relationship between
ArtistsandAlbums. - One-to-many relationship between
AlbumsandSongs. - One-to-many relationship between
UsersandPlaylists. - One-to-many relationship between
PlaylistsandPlaylist_Songs. - One-to-many relationship between
SongsandPlaylist_Songs.
- One-to-many relationship between
Variant 5: E-commerce Product Catalog Database
Scenario: Design a database for an e-commerce platform to manage products, categories, brands, suppliers, and product reviews.
Database Schema:
- Tables:
Products:product_id(integer, Primary Key)product_name(character varying)description(text)price(numeric)category_id(integer, Foreign Key referencingCategories(category_id))brand_id(integer, Foreign Key referencingBrands(brand_id))supplier_id(integer, Foreign Key referencingSuppliers(supplier_id))
Categories:category_id(integer, Primary Key)category_name(character varying)
Brands:brand_id(integer, Primary Key)brand_name(character varying)
Suppliers:supplier_id(integer, Primary Key)supplier_name(character varying)supplier_contact(character varying)
Product_Reviews:review_id(integer, Primary Key)product_id(integer, Foreign Key referencingProducts(product_id))rating(integer) - e.g., 1 to 5 stars.comment(text, Nullable)review_date(timestamp)
- Relationships:
- One-to-many relationship between
CategoriesandProducts. - One-to-many relationship between
BrandsandProducts. - One-to-many relationship between
SuppliersandProducts. - One-to-many relationship between
ProductsandProduct_Reviews.
- One-to-many relationship between
Variant 6: Event Ticketing System Database
Scenario: Design a database for an event ticketing system to manage events, venues, tickets, customers, and orders.
Database Schema:
- Tables:
Events:event_id(integer, Primary Key)event_name(character varying)event_date(timestamp)venue_id(integer, Foreign Key referencingVenues(venue_id))
Venues:venue_id(integer, Primary Key)venue_name(character varying)venue_address(character varying)capacity(integer)
Tickets:ticket_id(integer, Primary Key)event_id(integer, Foreign Key referencingEvents(event_id))ticket_type(character varying) - e.g., “General Admission”, “VIP”.price(numeric)quantity_available(integer)
Customers:customer_id(integer, Primary Key)first_name(character varying)last_name(character varying)email(character varying)
Orders:order_id(integer, Primary Key)customer_id(integer, Foreign Key referencingCustomers(customer_id))order_date(timestamp)
Order_Tickets: (Intersection table)order_ticket_id(integer, Primary Key) - Unique identifier for each ticket item in an order.order_id(integer, Foreign Key referencingOrders(order_id))ticket_id(integer, Foreign Key referencingTickets(ticket_id))quantity(integer)price(numeric) - Price of the ticket at the time of order.
- Relationships:
- One-to-many relationship between
VenuesandEvents. - One-to-many relationship between
EventsandTickets. - One-to-many relationship between
CustomersandOrders. - One-to-many relationship between
OrdersandOrder_Tickets. - One-to-many relationship between
TicketsandOrder_Tickets.
- One-to-many relationship between
Submission Instructions:
Step 1: Capture a High-Quality Screenshot of Your ER Diagram
- Maximize ERD Canvas: In pgAdmin 4, ensure your entire ER Diagram is visible on the screen. You might need to zoom out slightly or use the “Auto Align” feature again to ensure all tables and relationships are clearly displayed and not overlapping or cut off.

- Take a Screenshot: Capture a screenshot of your entire pgAdmin 4 window, clearly showing the ER Diagram you have created.
- Review Screenshot Quality: Open the screenshot and verify that:
- The entire ER Diagram is visible.
- Table names, column names, data types, primary keys, foreign keys, and relationships are clearly readable.
- The screenshot is not blurry or pixelated. If it’s unclear, retake the screenshot.
- Save the Screenshot: Save the screenshot as an image file (e.g.,
.png,.jpg). Name the file informatively, such asVariant[Variant Number]_ERD_Screenshot_[YourLastName]_[YourFirstName].png(e.g.,Variant1_ERD_Screenshot_Smith_John.png).
Step 2: Upload Screenshot to Google Drive
- Open Google Drive: Go to your Google Drive account in a web browser.
- Navigate to Submission Folder (Optional but Recommended): You may want to create a new folder in your Google Drive specifically for this Databases course or assignment submissions to keep things organized.
- Upload File: Click the “+ New” button (or “Upload”) and select “File upload”. Choose the screenshot image file you saved in Step 7. Wait for the upload to complete.
Step 3: Set Share Permissions for the Screenshot on Google Drive
- Locate Uploaded File: Find the screenshot file you just uploaded in your Google Drive.
- Get Shareable Link: Right-click on the screenshot file and select “Get link” (or “Share”).
- Change Link Settings: In the sharing dialog that appears, click on “Change” next to “Restricted” (or the current access setting).
- Select “Anyone with the link”: Choose the option “Anyone with the link” from the dropdown menu.
- Set Permission to “Viewer”: Ensure the permission is set to “Viewer” (it should be by default).
- Copy Link: Click the “Copy link” button. The link to your screenshot is now copied to your clipboard.
- Click “Done”: Close the sharing dialog.
Step 4: Submit the Google Drive Link in Google Sheets
- Open the Google Sheet: google sheets for this task
- Find Your Row: Locate your name or student ID in the first column of the Google Sheet. Your submission cell will be in the corresponding row.
- Insert Link as a Comment: * Click on the cell designated for your submission. * Right-click on the cell and select “Insert comment” (or “Comment”). * Paste the Google Drive link you copied in Step 3 into the comment box. * Click “Comment” or the “Post” button to save the comment with the link.
- Verify Submission: Double-check that your comment is visible in the cell and that you’ve pasted the link correctly.
Important Reminders:
- Ensure “Anyone with the link can view” access is set on Google Drive. If this is not set correctly, your teacher will not be able to see your screenshot.
- Test your link! Open the link in a private browsing window or on a different device to confirm it works as expected and displays your screenshot.
- Submit by the deadline. Check the assignment instructions for the submission deadline.