Oracle
DDL ASSIGNMENT2 - Facebook Application
DDL ASSIGNMENT 2 - Facebook Application
Objective:
You are required to address a set of Data Definition Language (DDL) tasks for a Facebook Application System. Each query focuses on distinct DDL tasks, including the creation of tables, application of constraints, and establishment of relationships between tables.
Requirements:
You will need to complete at least 20 different DDL tasks, covering table creation, primary keys, foreign keys, constraints, and indexes. Each task represents a key part of designing the structure of the Facebook Application System.
Question 1: Create the USER Table
Write a DDL SQL statement to create a USER table with the following requirements:
user_idas a primary key with auto-increment functionality.first_nameas a string of maximum length 255 characters, not null.last_nameas a string of maximum length 255 characters, not null.emailas a unique string, not null.passwordas a string of maximum length 100 characters, not null.date_of_birthas a date field, not null.current_subscription_type_idas a foreign key referencing the SUBSCRIPTION_TYPE table.created_atas a datetime field, default it to system timestamp, not null.
Question 2: Create the POST Table with Constraints
Create a POST table with the following specifications:
post_idas a primary key with auto-increment functionality.user_idas a foreign key referencing the USER table, not null.contentas a string with a maximum length of 500 characters, not null.created_atas a datetime field, default it to system timestamp, not null.
Question 3: Create the FRIEND Table
Define a FRIEND table with the following details:
user_idas a foreign key referencing the USER table.friend_user_idas a foreign key referencing the USER table (indicating a friendship between two users).statusas a string (e.g., "Accepted", "Pending", "Blocked"), not null.created_atas a datetime field, default it to system timestamp, not null.
Question 4: Create the COMMENT Table with a Foreign Key
Define a COMMENT table:
comment_idas a primary key with auto-increment functionality.contentas a string of maximum length 255 characters, not null.created_atas a datetime field, default it to system timestamp, not null.post_idas a foreign key referencing the POST table, not null.user_idas a foreign key referencing the USER table, not null.
Question 5: Define the REACTION Table
Write the SQL statement to create a REACTION table, which tracks user reactions on posts or comments. This will include:
reaction_idas a primary key with auto-increment functionality.reaction_typeas a string (e.g., "Like", "Love", "Haha"), not null.post_idas a foreign key referencing the POST table (can be null), not null.comment_idas a foreign key referencing the COMMENT table (can be null), not null.user_idas a foreign key referencing the USER table, not null.created_atas a datetime field, default it to system timestamp, not null.
Question 6: Create the PAGE Table
Create a PAGE table:
page_idas a primary key with auto-increment functionality.page_nameas a string with a maximum length of 255 characters, not null.created_atas a datetime field, default it to system timestamp, not null.owner_idas a foreign key referencing the USER table (page owner), not null.
Question 7: Define the MESSAGE Table with Relationships
Write the SQL statement to create a MESSAGE table that includes:
message_idas a primary key with auto-increment functionality.message_contentas a string with a maximum length of 500 characters, not null.created_atas a datetime field, default it to system timestamp, not null.sender_idas a foreign key referencing the USER table, not null.receiver_idas a foreign key referencing the USER table, not null.
Question 8: Create the SUBSCRIPTION_TYPE Table with Constraints
Write a DDL SQL statement to create a SUBSCRIPTION_TYPE table:
subscription_type_idas a primary key with auto-increment functionality.subscription_typeas a string (e.g., "Free", "Premium"), not null.active_flagas a boolean, default to true, not null.validity_daysas a number, not null.created_atas a datetime field, default it to system timestamp, not null.- Add a
CHECKconstraint to ensure thesubscription_typeis in ("Free", "Standard:, "Premium").
Question 9: Create the USER_SUBSCRIPTION Table with Constraints
Write a DDL SQL statement to create a USER_SUBSCRIPTION table:
subscription_idas a primary key with auto-increment functionality.user_idas a foreign key referencing the USER table.subscription_type_idas a foreign key referencing the SUBSCRIPTION_TYPE table, not null.start_dateas a date field, not null.end_dateas a date field, nullable.active_flagas a boolean, default to true, not null.created_atas a datetime field, default it to system timestamp, not null.- Add a
CHECKconstraint to ensure theend_dateis afterstart_date.
Question 10: Create the SUBSCRIPTION_PAYMENT Table with Constraints
Write a DDL SQL statement to create a SUBSCRIPTION_PAYMENT table:
payment_idas a primary key with auto-increment functionality.subscription_idas a foreign key referencing the USER_SUBSCRIPTION table, not null.amount_paidas a decimal (10, 2), not null.payment_dateas a datetime, not null.- Add a
CHECKconstraint to ensure theamount_paidis greater than 0.
Question 11: Create the GROUP Table
Define a GROUP table with the following specifications:
group_idas a primary key with auto-increment functionality.group_nameas a string of maximum length 255 characters, not null.created_atas a timestamp, not null.created_user_idas a foreign key referencing the USER table, not null.created_atas a datetime field, default it to system timestamp, not null.
Question 12: Create the EVENT Table
Write a DDL SQL statement to create an EVENT table with the following details:
event_idas the primary key with auto-increment functionality.event_nameas a string of maximum length 255 characters, not null.event_dateas a date field, not null.event_start_timeas a time field, not null.event_end_timeas a time field, not null.created_user_idas a foreign key referencing the USER table, not null.created_atas a datetime field, default it to system timestamp, not null.
Question 13: Create the ADVERTISEMENT Table
Write a DDL SQL statement to create an ADVERTISEMENT table:
ad_idas the primary key with auto-increment functionality.ad_contentas a string with a maximum length of 255 characters, not null.posted_atas a timestamp, defaulting to the current timestamp, not null.page_idas a number, not null.created_atas a datetime field, default it to system timestamp, not null.
Question 14: Create the AUDIT_LOG Table
Define an AUDIT_LOG table to track changes in the Facebook application system:
log_idas a primary key with auto-increment functionality.log_dateas a datetime field, not null.actionas a string to describe the action performed.user_idas a foreign key referencing the USER table.
Question 15: Add a Column to the USER Table
Write a SQL statement to add a phone_number column of type VARCHAR(15) to the USER table.
Question 16: Alter a Column in the PAGE Table
Write a SQL statement to alter the page_name column in the PAGE table, increasing its length to 500 characters.
Question 17: Drop a Column from the COMMENT Table
Write a SQL statement to drop the created_at column from the COMMENT table.
Question 18: Rename the AUDIT_LOG Table
Write a SQL statement to rename the AUDIT_LOG table to AUDIT_LOGS.
Question 19: Drop the GROUP Table
Write a SQL statement to drop the GROUP table.
Question 20: Add a Compostire Primary Key
Set up a composite primary key using user_id and friend_user_id on FRIEND table.
Question 21: Alter the ADVERTISEMENT Table to Add a Foreign Key column
Write a SQL statement to add a event_id foreign key to the ADVERTISEMENT table, referencing the EVENT table.
Question 22: Add a Foreign Key to the ADVERTISEMENT Table
Add a foreign key in the ADVERTISEMENT table to reference the PAGE table.
Question 23: Add a CHECK Constraint on the FRIEND Table
Write a SQL statement to add a CHECK constraint to the FRIEND table ensuring that user_id and friend_id are not the same.
Question 24: Add a CHECK Constraint on the FRIEND Table
Write a SQL statement to add a CHECK constraint to the FRIEND table ensuring that status is ("Accepted" or "Pending" or "Blocked").
Question 25: Add a CHECK Constraint on the REACTION Table
Write a SQL statement to add a CHECK constraint to the REACTION table ensuring that reaction_type is ( "Like" or "Love" or "Haha")
Question 26: Add a UNIQUE Constraint on the PAGE Table
Write a SQL statement to add a UNIQUE constraint to the PAGE table ensuring that the page_name is not repeated.
Question 27: Add Indexes to the USER and POST Tables
Write SQL statements to:
- Add an index on the
last_namecolumn in the USER table. - Add an index on the
created_atcolumn in the POST table.
Question 28: Drop an Index from the POST Table
Write a SQL statement to drop the index on the created_at column in the POST table.
Question 29: Enforce UNIQUE constraints on all applicable tables.
Apply UNIQUE constraints to columns across the entire database wherever duplicate data is not permitted.
GOOD LUCK WITH YOUR ASSIGNMENT!!!
Don't forget to contact us if you need any further assistance with your assignments, and most importantly, for a manual review and approval of your work.
To gain complete access, login with gmail or outlook, no need of signup. click here
Sample ERD Data Model for Facebook Application


Comments Not Found