0% found this document useful (0 votes)
17 views7 pages

BankDB Balqis

The document provides SQL syntax to create tables for a banking database including tables for banks, employees, customers, and accounts. It also includes INSERT statements to add initial records to each table. The document then lists exercises to alter the tables by adding, removing, and modifying columns and capturing the table structure before and after each alteration.

Uploaded by

pandamalaya10
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)
17 views7 pages

BankDB Balqis

The document provides SQL syntax to create tables for a banking database including tables for banks, employees, customers, and accounts. It also includes INSERT statements to add initial records to each table. The document then lists exercises to alter the tables by adding, removing, and modifying columns and capturing the table structure before and after each alteration.

Uploaded by

pandamalaya10
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/ 7

Exercise: Run the following syntax.

CREATE TABLE BANK


(BankID INTEGER NOT NULL UNIQUE,
BankName VARCHAR(20) NOT NULL,
BankAddress VARCHAR(20),
BankPhoneNumber VARCHAR(20),
PRIMARY KEY(BankID));

CREATE TABLE EMPLOYEE


(EmpID INTEGER NOT NULL UNIQUE,
EmpLName VARCHAR(50) NOT NULL,
EmpFName VARCHAR(20),
EmpAddress VARCHAR(50),
EmpPosition VARCHAR(50),
BankID INTEGER,
PRIMARY KEY(EmpID),
FOREIGN KEY (BankID) REFERENCES BANK);
CREATE TABLE CUSTOMER
(CustomerID INTEGER NOT NULL UNIQUE,
FirstName VARCHAR(50),
LastName VARCHAR(20) NOT NULL,
StreetAddress VARCHAR(50),
City VARCHAR(20),
State VARCHAR(10),
ZIP VARCHAR(10),
BankID INTEGER,
PRIMARY KEY(CustomerID),
FOREIGN KEY(BankID) REFERENCES BANK);

CREATE TABLE ACCOUNT


(CustomerID INTEGER NOT NULL ,
AccountNumber INTEGER NOT NULL UNIQUE,
AccountType VARCHAR(20),
DateOpened VARCHAR(20),
Balance FLOAT,
PRIMARY KEY(AccountNumber),
FOREIGN KEY(CustomerID) REFERENCES CUSTOMER);
Exercise: Insert the record into the table using insert syntax. Save the query and paste
in your word.

INSERT INTO BANK


VALUES (100, 'maybank', 'Teluk Intan, Perak', '05-4567899');
VALUES (101, 'BSN', 'Ipoh, Perak', '05-3456789');
VALUES (102, 'BIMB', 'Tapah, Perak', '05-7893456');
VALUES (103, 'CIMB', 'Kampar, Perak', '05-2334567');

INSERT INTO EMPLOYEE


VALUES (120, 'Rahim', 'Rahimah', 'Langkap, Perak', 'Clerk', 100);
VALUES (121, 'Khairil', 'Khairiyah', 'Temoh, Perak', ‘Executive', 101);
VALUES (122, 'Hassan', 'Hussin', 'Tapah, Perak', 'Clerk', 101);
VALUES (123, 'Ali', 'Mamat', 'Ipoh, Perak', 'Senior Executive', 101);
VALUES (124, 'Israf', 'Maisarah', 'Tapah, Perak', 'Executive', 102);
VALUES (125, 'Hakimi', 'Nasrul', 'Kampar, Perak', 'Clerk', 102);
VALUES (126, 'Ali', 'Muhamad', 'Kuantan', 'CEO', 103);
INSERT INTO CUSTOMER
VALUES (1001, 'Joseph', 'Smith', '123 Lexington', 'Smithville', 'KY', 91232, 100);
VALUES (1002, 'Alberta', 'Jones', '12 Davis Ave.', 'Smithville', 'KY', 91232, 101);
VALUES (1003, 'Nathanial', 'Axe', '433 Grinder Ln.', 'Broadville', 'GA', 81992, 102);
VALUES (1004, 'Paulina', 'Builder', '661 Parker Rd.', 'Streetville', 'GA', 81990, 103);
VALUES (1005, 'Mamat', 'Ali', 'Teluk Intan', 'Ipoh', 'Perak', 18500, 103);

INSERT INTO ACCOUNT


VALUES (1004, 1122, 'Checking', '13/11/1998', 800);
VALUES (1004, 3322, 'Savings', '22/08/1994', 500);
VALUES (1003, 4422, 'Checking', '12/01/1994', 6000);
VALUES (1003, 4433, ' Savings', '12/01/1994', 9000);
VALUES (1002, 8811, ' Savings', '01/05/1992', 1000);
VALUES (1001, 9980, ' Savings', '10/12/1989', 2000);
VALUES (1001, 9987, 'Checking', '10/12/1989', 4000);
Exercise:
Create query for each and save the query. Snap the output (use snipping
tool) before and after Alter

1.Add EmployeeDOB Date in Employee Table


ALTER TABLE EMPLOYEE
ADD EmployeeDOB DATE;

Before

After
2. Add CustomerPhone varchar (20) in Customer Table

ALTER TABLE CUSTOMER


ADD CustomerPhone VARCHAR(20);

Before

After
3. Drop Column EmployeeDOB

ALTER TABLE EMPLOYEE


DROP COLUMN EmployeeDOB;

Before

AF

After

You might also like