Name: Muhammad Abdullah
Database Administration and Management-y4
ID : F2022105208
LAB 4
create database BankDB;
create table Customers
(
CustomerID int primary key,
Name varchar(50),
Email varchar(50),
Phone varchar (15)
);
create TABLE Accounts
(
AccountID int primary KEY,
CustomerID int FOREIGN KEY REFERENCES Customers(CustomerID),
AccountType varchar (20),
Balance decimal(10, 2)
);
insert into Customers (CustomerID, Name, Email, Phone)
VALUES
(1, 'Ahmed', '
[email protected]', '1234567890'),
(2, 'Taha', '
[email protected]', '9876543210'),
(3, 'Ali', '
[email protected]', '5678901234');
insert into Accounts (AccountID, CustomerID, AccountType, Balance)
VALUES
(101, 1, 'Savings', 1500.00),
(102, 2, 'Checking', 25300.00),
(103, 3, 'Savings', 800.00);
update Customers
SET Phone = '1112223333'
Where Name = 'Ahmed';
select * from Customers
Name: Muhammad Abdullah
ID : F2022105208
-- Delete Account with Balance Less Than 1000
Delete from Accounts
Where Balance < 1000;
select * from Accounts
select Name, AccountType
from Customers
JOIN Accounts
on Customers.CustomerID = Accounts.CustomerID;
Select Name, AccountType, Balance
FROM Customers
LEFT JOIN Accounts
on Customers.CustomerID = Accounts.CustomerID;
Name: Muhammad Abdullah
ID : F2022105208
Select AccountType,SUM(Balance)
as TotalBalance
From Accounts
GROUP BY AccountType;
-- Create a Full Backup
BACKUP DATABASE BankDB to DISK = 'C:\Backups\BankDB_Full.bak';
insert into Accounts (AccountID, CustomerID, AccountType, Balance)
VALUES
(104, 2, 'Savings', 3000.00);
-- Create a Differential Backup
BACKUP DATABASE BankDB to DISK = 'C:\Backups\BankDB_Diff.bak' WITH DIFFERENTIAL;
update Accounts
set Balance = 2000.00
Where AccountID = 101;
select * from Accounts
-- Create a Transaction Log Backup
BACKUP LOG BankDB to DISK = 'C:\Backups\BankDB_Log.trn';
Name: Muhammad Abdullah
ID : F2022105208
-- Drop Accounts Table
DROP table Accounts;
-- Restore from Full Backup
RESTORE DATABASE BankDB from DISK = 'C:\Backups\BankDB_Full.bak' WITH RECOVERY;
-- Apply Differential Backup
RESTORE DATABASE BankDB from DISK = 'C:\Backups\BankDB_Diff.bak' WITH RECOVERY;
-- Apply Transaction Log Backup
RESTORE LOG BankDB from DISK = 'C:\Backups\BankDB_Log.trn' WITH RECOVERY;
-- Verify Final Data State
SELECT * FROM Customers c
LEFT JOIN Accounts a
ON c.CustomerID = a.CustomerID;