Databases | Tasks for Practical Class 3
Creating, Modifying, and Deleting Tables in SQL
Variant 1: Online Bookstore Database
Variant 1: Online Bookstore Database
Scenario: You are tasked with setting up a database for an online bookstore. This database will initially manage books and their authors.
Table Schemas:
bookstable:book_id: Unique identifier for each book (auto-incrementing integer, primary key).title: Title of the book (text, not null, maximum length 100 characters).isbn: International Standard Book Number (text, unique, maximum length 20 characters).publication_year: Year of publication (integer).genre: Genre of the book (text, maximum length 50 characters).
authorstable:author_id: Unique identifier for each author (auto-incrementing integer, primary key).author_name: Name of the author (text, not null, maximum length 100 characters).nationality: Nationality of the author (text, maximum length 50 characters).birth_date: Date of birth of the author (date).
Tasks:
- Create the
booksandauthorstables in your database using theCREATE TABLEstatement. - Add two new columns to the
bookstable:price(decimal) andstock_quantity(integer, default value 0). - Modify the
genrecolumn in thebookstable to have a maximum length of 75 characters and change the data type ofpublication_yeartoSMALLINT. - Rename the
author_namecolumn in theauthorstable tonameand rename thenationalitycolumn tocountry. - Drop the
birth_datecolumn from theauthorstable and thegenrecolumn from thebookstable. - Delete the
authorstable from the database using theDROP TABLEstatement.
Variant 2: Event Management Database
Variant 2: Event Management Database
Scenario: You are building a database to manage events and venues for an event planning company.
Table Schemas:
eventstable:event_id: Unique identifier for each event (auto-incrementing integer, primary key).event_name: Name of the event (text, not null, maximum length 100 characters).event_date: Date of the event (date, not null).start_time: Time the event starts (time).category: Category of the event (text, maximum length 50 characters).
venuestable:venue_id: Unique identifier for each venue (auto-incrementing integer, primary key).venue_name: Name of the venue (text, not null, maximum length 100 characters).address: Address of the venue (text, maximum length 200 characters).capacity: Maximum capacity of the venue (integer).venue_type: Type of venue (e.g., ‘hall’, ‘stadium’, ‘park’) (text, maximum length 50 characters).
Tasks:
- Create the
eventsandvenuestables in your database. - Add two new columns to the
eventstable:description(text) andis_cancelled(boolean, default false). - Modify the
categorycolumn in theeventstable to beNOT NULLand change the data type ofcapacityin thevenuestable toBIGINT. - Rename the
event_namecolumn in theeventstable totitleand rename thevenue_namecolumn in thevenuestable toname. - Drop the
start_timecolumn from theeventstable and thevenue_typecolumn from thevenuestable. - Delete the
venuestable from the database.
Variant 3: Music Library Database
Variant 3: Music Library Database
Scenario: You are creating a database to manage a personal music library, tracking songs and artists.
Table Schemas:
songstable:song_id: Unique identifier for each song (auto-incrementing integer, primary key).song_title: Title of the song (text, not null, maximum length 100 characters).duration_seconds: Duration of the song in seconds (integer).release_year: Year the song was released (integer).genre: Genre of the song (text, maximum length 50 characters).
artiststable:artist_id: Unique identifier for each artist (auto-incrementing integer, primary key).artist_name: Name of the artist (text, not null, maximum length 100 characters).origin_country: Country of origin of the artist (text, maximum length 50 characters).formation_year: Year the artist was formed (integer).
Tasks:
- Create the
songsandartiststables in your database. - Add two new columns to the
songstable:album_name(text, maximum length 100 characters) andplay_count(integer, default 0). - Modify the
genrecolumn in thesongstable to have a maximum length of 75 characters and change the data type ofduration_secondstoREAL. - Rename the
song_titlecolumn in thesongstable totitleand rename theartist_namecolumn in theartiststable toname. - Drop the
release_yearcolumn from thesongstable and theformation_yearcolumn from theartiststable. - Delete the
artiststable from the database.
Variant 4: Simple Blogging Platform Database
Variant 4: Simple Blogging Platform Database
Scenario: You are designing a database for a simple blogging platform to manage blog posts and categories.
Table Schemas:
poststable:post_id: Unique identifier for each post (auto-incrementing integer, primary key).post_title: Title of the blog post (text, not null, maximum length 200 characters).content: Content of the blog post (text).publication_date: Date the post was published (date, default current date).is_published: Status of publication (boolean, default false).
categoriestable:category_id: Unique identifier for each category (auto-incrementing integer, primary key).category_name: Name of the category (text, not null, unique, maximum length 50 characters).description: Description of the category (text, maximum length 200 characters).created_at: Timestamp when the category was created (timestamp with time zone, default current timestamp).
Tasks:
- Create the
postsandcategoriestables in your database. - Add two new columns to the
poststable:author_name(text, maximum length 100 characters) andview_count(integer, default 0). - Modify the
post_titlecolumn in thepoststable to have a maximum length of 255 characters and change the data type ofpublication_datetoTIMESTAMP. - Rename the
post_titlecolumn in thepoststable totitleand rename thecategory_namecolumn in thecategoriestable toname. - Drop the
is_publishedcolumn from thepoststable and thedescriptioncolumn from thecategoriestable. - Delete the
categoriestable from the database.
Variant 5: Recipe Database
Variant 5: Recipe Database
Scenario: You are creating a database to store recipes and their ingredients for a recipe application.
Table Schemas:
recipestable:recipe_id: Unique identifier for each recipe (auto-incrementing integer, primary key).recipe_name: Name of the recipe (text, not null, maximum length 100 characters).instructions: Cooking instructions (text).cuisine_type: Type of cuisine (e.g., ‘Italian’, ‘Mexican’, ‘Indian’) (text, maximum length 50 characters).preparation_time_minutes: Preparation time in minutes (integer).
ingredientstable:ingredient_id: Unique identifier for each ingredient (auto-incrementing integer, primary key).ingredient_name: Name of the ingredient (text, not null, unique, maximum length 100 characters).is_vegetarian: Indicates if the ingredient is vegetarian (boolean, default true).is_vegan: Indicates if the ingredient is vegan (boolean, default false).
Tasks:
- Create the
recipesandingredientstables in your database. - Add two new columns to the
recipestable:servings(integer, default 1) andrating(numeric, precision 2, scale 1, e.g., 4.5). - Modify the
cuisine_typecolumn in therecipestable to have a maximum length of 75 characters and change the data type ofpreparation_time_minutestoSMALLINT. - Rename the
recipe_namecolumn in therecipestable tonameand rename theingredient_namecolumn in theingredientstable toname. - Drop the
instructionscolumn from therecipestable and theis_vegancolumn from theingredientstable. - Delete the
ingredientstable from the database.
Variant 6: Simple Task Management Database
Variant 6: Simple Task Management Database
Scenario: You are building a database for a simple task management application to manage tasks and projects.
Table Schemas:
taskstable:task_id: Unique identifier for each task (auto-incrementing integer, primary key).task_name: Name of the task (text, not null, maximum length 100 characters).description: Description of the task (text).due_date: Date the task is due (date).status: Status of the task (e.g., ‘To Do’, ‘In Progress’, ‘Completed’) (text, maximum length 50 characters, default ‘To Do’).
projectstable:project_id: Unique identifier for each project (auto-incrementing integer, primary key).project_name: Name of the project (text, not null, maximum length 100 characters).start_date: Date the project started (date).end_date: Date the project is expected to end (date).priority: Priority of the project (e.g., ‘High’, ‘Medium’, ‘Low’) (text, maximum length 50 characters, default ‘Medium’).
Tasks:
- Create the
tasksandprojectstables in your database. - Add two new columns to the
taskstable:created_at(timestamp with time zone, default current timestamp) andis_urgent(boolean, default false). - Modify the
statuscolumn in thetaskstable to have a maximum length of 75 characters and change the data type ofdue_datetoTIMESTAMP. - Rename the
task_namecolumn in thetaskstable totitleand rename theproject_namecolumn in theprojectstable toname. - Drop the
descriptioncolumn from thetaskstable and theend_datecolumn from theprojectstable. - Delete the
projectstable from the database.
Submission Instructions
1. Perform the Tasks:
- For your selected variant, complete all the tasks outlined. This involves writing and executing SQL commands in pgAdmin 4 using PostgreSQL.
2. Document Your Work in a Google Doc:
- Create a new Google Document. example
- At the top of the document, clearly write:
- Your Name:
- Variant Number: (e.g., Variant 1: Online Bookstore Database)
- For each task within the variant, document the following:
- Task Number: (e.g., Task 1, Task 2, Task 3, etc.)
- SQL Command: Copy and paste the exact SQL command you executed in pgAdmin 4 for that task.
- Confirmation/Screenshot: Include a screenshot from pgAdmin 4 (showing the table created in the Object Browser) to visually confirm the successful execution of your command.
3. Submit Your Google Doc Link:
- Once you have completed documenting all tasks for your chosen variant in your Google Doc, ensure the document is shared so that your teacher can access it. Important: Set the sharing permissions to “Anyone with the link can Comment”.
- Go to the Google Sheet provided by your teacher for assignment submissions. Google Sheet
- Locate the column corresponding to your name.
- In the appropriate cell for this Database Assignment, paste the shareable link to your Google Doc.