0% found this document useful (0 votes)
18 views4 pages

Tables

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

Tables

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

Creating Tables and Inserting Records

CREATE TABLE Customers (

CustomerID INT PRIMARY KEY,


FirstName VARCHAR(50),

LastName VARCHAR(50),
DateOfBirth DATE,

Address VARCHAR(100),
PhoneNumber VARCHAR(15),

Email VARCHAR(50)
);

INSERT INTO Customers (CustomerID, FirstName, LastName, DateOfBirth,


Address, PhoneNumber, Email) VALUES

(1, 'John', 'Doe', '1985-04-15', '123 Main St, CityA', '555-1234',


'[email protected]'),
(2, 'Jane', 'Smith', '1990-07-22', '456 Maple Rd, CityB', '555-5678',
'[email protected]'),

(3, 'Mike', 'Brown', '1983-09-30', '789 Oak Dr, CityC', '555-8765',


'[email protected]'),

(4, 'Emily', 'White', '1995-01-18', '321 Pine Ln, CityD', '555-4321',


'[email protected]'),
(5, 'David', 'Johnson', '1988-05-05', '654 Cedar Ave, CityE', '555-6789',
'[email protected]');

CREATE TABLE Accounts (

AccountID INT PRIMARY KEY,


CustomerID INT,

AccountType VARCHAR(20),
Balance DECIMAL(10, 2),

DateOpened DATE,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)

);

INSERT INTO Accounts (AccountID, CustomerID, AccountType, Balance,


DateOpened) VALUES

(101, 1, 'Savings', 1500.00, '2022-01-10'),


(102, 2, 'Checking', 2000.00, '2022-02-15'),
(103, 3, 'Savings', 1200.00, '2022-03-20'),
(104, 4, 'Savings', 1800.00, '2022-04-25'),
(105, 5, 'Checking', 500.00, '2022-05-30');

CREATE TABLE Transactions (

TransactionID INT PRIMARY KEY,


AccountID INT,
TransactionType VARCHAR(20),
Amount DECIMAL(10, 2),
TransactionDate DATE,

FOREIGN KEY (AccountID) REFERENCES Accounts(AccountID)


);

INSERT INTO Transactions (TransactionID, AccountID, TransactionType,


Amount, TransactionDate) VALUES
(1001, 101, 'Deposit', 500.00, '2023-01-10'),

(1002, 102, 'Withdrawal', 300.00, '2023-01-15'),


(1003, 103, 'Deposit', 700.00, '2023-01-20'),

(1004, 104, 'Withdrawal', 400.00, '2023-01-25'),


(1005, 105, 'Deposit', 100.00, '2023-01-30');

CREATE TABLE Loans (

LoanID INT PRIMARY KEY,


CustomerID INT,
LoanAmount DECIMAL(10, 2),
InterestRate DECIMAL(5, 2),
LoanDate DATE,

LoanType VARCHAR(20),
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)

);
INSERT INTO Loans (LoanID, CustomerID, LoanAmount, InterestRate,
LoanDate, LoanType) VALUES

(2001, 1, 10000.00, 5.5, '2023-02-10', 'Personal'),


(2002, 2, 15000.00, 6.0, '2023-03-15', 'Home'),

(2003, 3, 12000.00, 5.8, '2023-04-20', 'Car'),


(2004, 4, 5000.00, 6.5, '2023-05-25', 'Education'),

(2005, 5, 8000.00, 5.9, '2023-06-30', 'Personal');

You might also like