PostgreSQL
DDL ASSIGNMENT1 - Banking Application System
Objective:
You are required to address a set of Data Definition Language (DDL) for a Banking 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 Banking Application System.
Question 1: Create the CITY Table with Constraints
Write a DDL SQL statement to create an CITY table:
city_idas a primary key with auto-increment functionality.country_nameas a string with a maximum length of 50 characters, and not null.city_nameas a string with a maximum length of 50 characters, not null.created_atas a datetime field, default to system timestamp, not null.- Add a
UNIQUEconstraint on country_name + city_name to ensure that there are no duplicates.
Question 2: Create the BRANCH Table with Default Values
Create a BRANCH table:
branch_idas a primary key with auto-increment functionality.branch_nameas a string with a maximum length of 255 characters, not null.branch_locationas a string with a maximum length of 255 characters.city_idas a foreign key referencing the CITY table.- Add a default value for
branch_locationas 'Main Branch'.
Question 3: Define the EMPLOYEE Table with Relationships
Write the SQL statement to create an EMPLOYEE table that includes:
employee_idas a primary key with auto-increment functionality.first_nameas strings, not null.last_nameas strings, not null.hire_dateas a date field, not null.salaryas a decimal, not null.branch_idas a foreign key referencing the BRANCH table.city_idas a foreign key referencing the CITY table.created_atas a date field, not null.
Question 4: Create the CUSTOMER Table
Write DDL SQL statement to create a CUSTOMER table with the following requirements:
customer_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.genderas a char of maximum length 1, not null ('M' or 'F').ID_typeas a string of maximum length 50 characters (e.g., "passport" or "driving license"), not null.ID_numberas a string of maximum length 255 characters (passport number or others), not null.emailas a string, not null.phone_numberas a string, not null.addressas a string, not null.city_idas a foreign key referencing the CITY table.created_atas a datetime field, default to system timestamp, not null.- Add a
CHECKconstraint to ensure that thegenderis either 'M' or 'F'.
Question 5: Create the ACCOUNT Table with Constraints
Create an ACCOUNT table with the following specifications:
account_idas a primary key with auto-increment functionality.account_typeas a variable character string, not to exceed 50 characters, and cannot be null.balanceas a decimal with precision (12, 2), not null.customer_idas a foreign key referencing the CUSTOMER table, not null.created_atas a datetime field, default to system timestamp, not null.- Add a
CHECKconstraint to ensure that thebalanceis greater than or equal to 0. - Add a
CHECKconstraint to ensure that theaccount_typeis either savings or checking or loan account.
Question 6: Create the CARD Table
Write a DDL SQL statement to create a CARD table with the following details:
card_idas the primary key with auto-increment functionality.card_numberas a string with a maximum length of 16 characters, unique and not null.card_typeas a string with a maximum length of 50 characters (e.g., 'credit', 'debit'), not null.expiration_dateas a date field, not null.max_credit_limitmaximum allowed limit in case of a credit card, not null.available_credit_limitcurrent available limit in case of a credit card, not null.account_idas a foreign key referencing the ACCOUNT table, not null.created_atas a datetime field, default to system timestamp, not null.
Question 7: Create the TRANSACTION Table
Define a TRANSACTION table with the following details:
transaction_idas a primary key with auto-increment functionality.transaction_dateas a date field, defaulted to the current date, not null.amountas a decimal (10, 2), not null.transaction_typeas a string with a maximum length of 50 characters (e.g., "debit" or "credit"), not null.payment_modeas a string with CHECK constraint ('ATM', 'cash deposit', 'loan payment', 'fund transfer', 'card' fees', 'credit card'), not null.account_idas a foreign key referencing the ACCOUNT table, with a maximum length of 50 characters, not null.transaction_statusas a string with a maximum length of 150 characters.descriptionas a datetime field, default to system timestamp, not null.- Add a
CHECKconstraint to ensure the transaction type is either 'debit' or 'credit'. - Add a
CHECKconstraint to ensure the transaction_status is either 'processing' or 'declined' or 'completed'.
Question 8: Create the ACCOUNT_HISTORY Table
Write a DDL SQL statement to create an ACCOUNT_HISTORY table with the details:
history_idas the primary key with auto-increment functionality.account_idas a foreign key referencing the ACCOUNT table, not null.balance_beforeas a decimal, not null.balance_afteras a decimal, not null.latest_recordas a boolean, default true, not null.transaction_idas a foreign key referencing the TRANSACTION table, not null.created_atas a datetime field, default to system timestamp, not null.
Question 9: Create the LOAN Table with a Foreign Key
Define a LOAN table:
loan_idas a primary key with auto-increment functionality.loan_amountas a decimal, not null.number_of_monthly_instalmentsnumeric, not null.interest_rateas a decimal (5, 2), not null.loan_start_dateas a date field, not null.loan_end_dateas a date field, nullable.account_idas a foreign key referencing the ACCOUNT table, not null.created_atas a datetime field, default to system timestamp, not null.created_employee_idforeign key referencing table, employee who issued the loan.
Question 10: Define the LOAN_INSTALMENTS Table
Write the SQL statement to create a one-to-many relationship between loan and its instalments. This will require the LOAN_INSTALMENTS table, which includes:
instalment_idas a primary key with auto-increment functionality.loan_idas a foreign key referencing the LOAN table, not null.instalment_amountmonthly loan payment amount, not null.due_date1st day of a given month, not null.paid_statusboolean, default false not null.created_atas a datetime field, default to system timestamp, not null.
Question 11: Create the LOAN_PAYMENT Table
Define a LOAN_PAYMENT table with the following specifications:
instalment_idas a foreign key referencing the LOAN table, not null.transaction_idas a foreign key referencing the TRANSACTION table, not null.- Setup composite primary key with instalment_id and transaction_id
Question 12: Create the BENEFICIARY Table with Constraints
Write a DDL SQL statement to create an BENEFICIARY table:
beneficiary_idas a primary key with auto-increment functionality.primary_consumeras a foreign key referencing the CONSUMER table, not null.beneficiary_bankbeneficiary bank name, not null.beneficiary_namebeneficiary full name, not null.beneficiary_account_numberbeneficiary bank account number, not null.beneficiary_swiftbeneficiary bank swift number.beneficiary_ibanbeneficiary bank iban number.nick_namegive by consumer while adding a beneficiary.created_atas a datetime field, default to system timestamp, not null.
Question 13: Create the FUND_TRANSFER Table with Constraints
Write a DDL SQL statement to create an FUND_TRANSFER table:
fund_transfer_idas a primary key with auto-increment functionality.beneficiary_idas a foreign key referencing the BENEFICIARY table, not null.transaction_idas a foreign key referencing the TRANSACTION table, not null.refund_transaction_idas a foreign key referencing the TRANSACTION table, nulltransfer_timestamptransaction date.transfer_statusas a string with CHECK constraint (e.g., 'processing', 'failed', 'completed'), not null.created_atas a datetime field, default to system timestamp, not null.
Question 14: Create the CUSTOMER_LOGIN Table
Write a DDL SQL statement to create an CUSTOMER_LOGIN table (one-to-one relationship with customer table):
customer_idas a foreign key referencing the CUSTOMER table, not null.login_idcan use alpha numeric login id or email as login id, not null.passwordmust encrypt the password before storing it in the database table.active_flagas numeric, 0 or 1, you can lock the customer login when required, not null.last_login_datetimeas timestamp, last successful login date for a given customer.created_atas a datetime field, default to system timestamp, not null.
Question 15: Create the AUDIT_LOG Table
Define an AUDIT_LOG table to track changes in the banking system:
log_idas a primary key with auto-increment functionality.log_dateas a date field, not null.actionas a string to describe the action performed.employee_idas a foreign key referencing the EMPLOYEE table.
Question 16: Create the OVERDRAFT_POLICY Table with Constraints
Write a DDL SQL statement to create an OVERDRAFT_POLICY table:
policy_idas a primary key with auto-increment functionality.max_overdraft_limitas a decimal, not null.- Add a
CHECKconstraint to ensure themax_overdraft_limitis greater than or equal to 0. interest_rateas a decimal (5, 2), not null.created_atas a datetime field, default to system timestamp, not null.
Question 17: Rename the OVERDRAFT_POLICY Table
Write a SQL statement to rename the OVERDRAFT_POLICY table to COMPANY_POLICY.
Question 18: Drop the COMPANY_POLICY Table
Write a SQL statement to drop the COMPANY_POLICY table.
Question 19: Add Indexes to the CUSTOMER and ACCOUNT Tables
Write SQL statements to:
- Add an index on the
last_namecolumn in the CUSTOMER table. - Add an index on the
account_typecolumn in the ACCOUNT table.
Question 20: Add a CHECK Constraint on the ACCOUNT Table
Write a SQL statement to add a CHECK constraint to the ACCOUNT table ensuring that the balance is greater than or equal to 0.
Question 21: Add a Primary Key to existing table
Add a primary key to the CUSTOMER_LOGIN table on customer_id column.
Question 22: Add a Foreign Key to the PAYMENT Table
Write a SQL statement to add a foreign key in the PAYMENT table to reference the ACCOUNT table.
Question 23: Add a Column to the EMPLOYEE Table
Write a SQL statement to add a phone_number column of type VARCHAR(15) to the EMPLOYEE table.
Question 24: Alter the CUSTOMER Table to Add a Foreign Key Column
Write a SQL statement to add a branch_id foreign key column to the CUSTOMER table, referencing the BRANCH table.
Question 25: Alter a Column in the CUSTOMER Table
Write a SQL statement to alter the email column in the CUSTOMER table, increasing its length to 255 characters.
Question 26: Drop a Column from the LOAN Table
Write a SQL statement to drop the loan_end_date column from the LOAN table.
Question 27: Drop an Index from the ACCOUNT Table
Write a SQL statement to drop the index on the account_type column in the ACCOUNT table.
Question 28: Add a default Current timestamp constraint on the EMPLOYEE Table
Write a SQL statement to add a current timestamp DEFAULT constraint to the EMPLOYEE table on the created_at column.
Question 29: Add a UNIQUE Constraint on the CUSTOMER Table
Write a SQL statement to add a UNIQUE constraint to the CUSTOMER table ensuring that the combination of id_type&id_number is not repeated.
Question 30: Enforce UNIQUE constraints on all applicable tables.
Apply UNIQUE constraints 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 Banking System

Database project tasks for a banking application in SQL

















Comments Not Found