0% found this document useful (0 votes)
8 views

DATABASE LAB 4 (1)

Uploaded by

f2022105208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DATABASE LAB 4 (1)

Uploaded by

f2022105208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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', 'ahmed@55.com', '1234567890'),
(2, 'Taha', 'taha@exe.com', '9876543210'),
(3, 'Ali', 'ali@555.com', '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;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy