CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
First_name VARCHAR(50),
Last_name VARCHAR(50),
Phone_number VARCHAR(15),
Email VARCHAR(100) UNIQUE,
Address TEXT
);
CREATE TABLE Accounts (
AccountID INT PRIMARY KEY,
CustomerID INT,
Account_type ENUM('Savings', 'Checking') NOT NULL,
Balance DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
Created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
CREATE TABLE ATMs (
ATMID INT PRIMARY KEY,
Location VARCHAR(255) NOT NULL,
Status ENUM('Active', 'Inactive') DEFAULT 'Active',
Last_maintenance DATE
);
CREATE TABLE Transactions (
TransactionID INT PRIMARY KEY,
AccountID INT,
ATMID INT,
Transaction_type ENUM('Withdrawal', 'Deposit', 'Transfer', 'Balance Inquiry')
NOT NULL,
Amount DECIMAL(15, 2) DEFAULT NULL,
Transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (AccountID) REFERENCES Accounts(AccountID),
FOREIGN KEY (ATMID) REFERENCES ATMs(ATMID)
);
CREATE TABLE Cards (
CardID INT PRIMARY KEY,
AccountID INT,
Card_number CHAR(16) UNIQUE NOT NULL,
Expiration_date DATE NOT NULL,
CVV CHAR(3) NOT NULL,
Card_status ENUM('Active', 'Blocked', 'Expired') DEFAULT 'Active',
FOREIGN KEY (AccountID) REFERENCES Accounts(AccountID)
);
INSERT INTO Customers (CustomerID, First_name, Last_name, Phone_number, Email,
Address) VALUES
(101, 'John', 'Doe', '+123456789', '
[email protected]', '123 Elm Street'),
(102, 'Jane', 'Smith', '+987654321', '
[email protected]', '456 Oak Avenue');
INSERT INTO Accounts (AccountID, CustomerID, Account_type, Balance) VALUES
(201, 101, 'Savings', 5000.00),
(202, 101, 'Checking', 2000.00),
(203, 102, 'Savings', 3000.00);
INSERT INTO ATMs (ATMID, Location, Status, Last_maintenance) VALUES
(301, 'Downtown Branch', 'Active', '2024-01-15'),
(302, 'Airport Terminal', 'Active', '2024-01-10');
INSERT INTO Transactions (TransactionID, AccountID, ATMID, Transaction_type,
Amount) VALUES
(401, 201, 301, 'Withdrawal', 500.00),
(402, 201, 301, 'Deposit', 1000.00),
(403, 202, 302, 'Withdrawal', 300.00),
(404, 203, 302, 'Balance Inquiry', NULL);
INSERT INTO Cards (CardID, AccountID, Card_number, Expiration_date, CVV,
Card_status) VALUES
(501, 201, '1234567812345678', '2025-12-31', '123', 'Active'),
(502, 202, '8765432187654321', '2026-06-30', '321', 'Active');
SELECT T.TransactionID, T.Transaction_type, T.Amount, T.Transaction_date,
A.Account_type
FROM Transactions T
JOIN Accounts A ON T.AccountID = A.AccountID
WHERE A.CustomerID = 101;
SELECT * FROM ATMs WHERE Status = 'Active';
SELECT C.First_name, C.Last_name, A.Balance
FROM Customers C
JOIN Accounts A ON C.CustomerID = A.CustomerID
WHERE A.Balance > 3000;
UPDATE ATMs
SET Status = 'Active', Last_maintenance = CURRENT_DATE
WHERE ATMID = 302;
DELETE FROM Transactions
WHERE TransactionID = 404;
SELECT A.AccountID, A.Account_type, A.Balance, C.Card_number, C.Card_status
FROM Accounts A
JOIN Cards C ON A.AccountID = C.AccountID;