Consider the following relational database:
Customer (custId, custName, custAddress, custPhone)
Account (AccountNumber, custId, TypeOfAccount, Balance)
Transaction (DateTimeofTransaction, AccountNumber, DebitORCredit, Amount)
The underlined attribute(s) in the relation forms the primary key. In relation Customer, the custID is
the unique identifier of a customer. The purposes of other attributes in Customer relation are self
explanatory. You may define the domain of different attributes. The TypeOfAccount attribute can
take the value (“Saving”, “Current”, “Salary”, “Other”). Please note that at a specific time of a date
only one transaction can be performed from an account. Please also note that the Account relation
has foreign key custID and Transaction relation has foreign key AccountNumber. Write and run the
following SQL queries on the database:
(i) Create the tables with the primary and foreign key constraints.
(ii) Insert at least 5 records in the first 2 tables and 20 records in the 3rd table.
(iii) List “Saving” Account details showing the AccountNumber, custName, custPhone,
Balance of all the accounts. These records should be shown in the order of custName.
(iv) Find all the transactions made by customer whose custID is “240002”.
(v) Find the list of those customers who have more than one account.
(vi) Find the total of Debit transactions made for Account Number “A0054”
(vii) Find the total of balance of all the accounts of a customer.
(viii) Find the list of customers whose name start with an alphabet “B”
(ix) List the pair of customers who share the same phone number.
(x) Find the list of the customers, who have not made any credit transaction since 1st January,
2023.
(i) Creating Tables with Primary and Foreign Key Constraints:
```sql
CREATE TABLE Customer (
custId INT PRIMARY KEY,
custName VARCHAR(100),
custAddress VARCHAR(255),
custPhone VARCHAR(15)
);
CREATE TABLE Account (
AccountNumber VARCHAR(10) PRIMARY KEY,
custId INT,
TypeOfAccount ENUM('Saving', 'Current', 'Salary', 'Other'),
Balance DECIMAL(10, 2),
FOREIGN KEY (custId) REFERENCES Customer(custId)
);
CREATE TABLE Transaction (
DateTimeofTransaction DATETIME,
AccountNumber VARCHAR(10),
DebitORCredit ENUM('Debit', 'Credit'),
Amount DECIMAL(10, 2),
FOREIGN KEY (AccountNumber) REFERENCES Account(AccountNumber),
PRIMARY KEY (DateTimeofTransaction, AccountNumber)
);
```
(ii) Inserting Records into the Tables:
```sql
-- Inserting records into Customer table
INSERT INTO Customer (custId, custName, custAddress, custPhone) VALUES
(240001, 'Alice Johnson', '123 Elm St', '555-1234'),
(240002, 'Bob Smith', '456 Oak Ave',
________ _______ __________ ______ _______ ______ ___ _________ __________ _______ __________.
__________ ___ ____ _________ ______ _______ __________ ________ ____.
________ __________ __________ _______ ______ _______ ______ ________ _____ _____ ____ _____.
______ __________ _________ __________ _____ _______ ________ __________.
___ _______ ________ _________ _________ _____ __________ ______ ______ _____ __________ _____.
_____ _____ _______ _________ ___ ________ ____ ______ _________.
__________ ___ _______ _____ _______ ___.
__________ _________ _________ _______ __________ ___.
_________ ___ _____ ___ _____ _______ ____ _____.
________ ________ _____ ___ _______.
________ _____ ______ _________ ______ _________ __________ __________ __________ _____ ________ ____.
___ __________ ________ ________ _______.
______ _______ ____ ________ ______ __________ ______ __________ ________ ___.
__________ ____ ____ ____ ________ ________ _________ ________ __________ _____ ______.
_______ ___ ____ ______ ________ _____ ______ ___ ________ _______.
________ ________ ______ _________ _______ ____.
_____ ______ ____ _________ _________.
____ ___ ____ ___ __________ ______ ______.
________ ____ _____ _________ _______ ___ ______ ____ ______ _________ ____.
___ _______ ______ ________ __________ __________ _____ ____.
___ _________ _________ _________ __________ _______ _____.
_______ ________ _________ ________ __________ _______ _________.
_______ __________ __________ __________ _______ _______ __________ _______ ________ ____ _________.
__________ __________ ____ _______ _______ __________ _____ ______.
______ _________ _________ ______ ____ _______.
_______ _______ ___ __________ _________ ______ ______ ___ ____ __________.
_______ _______ _____ __________ ______ ___ ________ ______ _______.
___ __________ _____ ______ ____ ____ ___ _______ _______.
________ ________ _____ ________ ___ _______ _____.
______ _______ ___ _______ ___ __________ _________ ____ __________.
_______ ____ _____ ______ ______ ________.
_________ _____ ________ _______ _________.
_________ ______ ______ _____ __________ _____ ______.
________ _________ ____ _________ ______ __________ _______ _________ _______ ________ _____ _____.
___ ______ __________ ___ ___ _______.
_________ __________ __________ ___ __________ ________ ____ _________.
____ ____ _______ _____ ___ ________ ______.
_____ ____ ______ _______ ___ _____ ___.
_________ _______ ______ _____ ________ ____ _____ ________.
__________ ________ _______ _________ _______ ________ ______ _____ ______ _________.
________ __________ ______ _________ _________ _____ __________ ___ ___.
____ __________ _________ _______ _____ _______ _______ _________ ______.
___ ________ __________ ___ _____ ____ ___ _________ ___ ___.
_________ _________ ______ ______ _____ _______.
_______ __________ __________ ______ ____ _______ ________ ___ _______ ______ ___ _______.
_______ _______ ___ ___ __________ ______ ____ ______ ________ ________.
________ ____ ___ ___ _________ _____ _______ _____.
___ __________ __________ ____ ________ _____.
__________ _______ __________ ________ ______ ________ ___ _________.
____ ___ _______ ______ ________ ____ ________ ______.
_________ _______ ___ ______ _________ ______.
_____ _______ _____ ________ _______ ___ ________ ___ __________.
______ ____ _______ ______ ________ ____ ______ ______ ________ _______ ________ ___.
_______ ____ ___ ____ _________ _________ ________ _______ __________ ___.
_________ ______ ________ ___ __________ ________ ________ __________ ______.
__________ ___ ______ ____ __________ ___ _____ _______ ____ ________.
___ ___ ________ _______ __________ _______ ______ ___ ________ ______.
________ ________ ______ ______ _________ ______ ____ _____ _____ _____.
____ ______ __________ _____ ________ _______ ___.
________ _________ __________ ________ _________ __________ ________.
________ _____.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required