0% found this document useful (0 votes)
61 views31 pages

Geehthan A/L Vinogobalan S55515: Activity 1

The document contains the details of a student named GEEHTHAN A/L VINOGOBALAN S55515. It outlines various database activities and SQL scripts they completed, including: 1. Creating tables for customers, sales, and products with attributes. 2. Creating additional tables for a vehicle service center with technicians, customers, vehicles, services, service details, and parts. 3. Altering tables and modifying data types. 4. Performing inserts, selects, deletes on tables including courses and students. 5. Creating tables for a banking database with branches, accounts, customers, loans, and transactions.

Uploaded by

GeehthanJI
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)
61 views31 pages

Geehthan A/L Vinogobalan S55515: Activity 1

The document contains the details of a student named GEEHTHAN A/L VINOGOBALAN S55515. It outlines various database activities and SQL scripts they completed, including: 1. Creating tables for customers, sales, and products with attributes. 2. Creating additional tables for a vehicle service center with technicians, customers, vehicles, services, service details, and parts. 3. Altering tables and modifying data types. 4. Performing inserts, selects, deletes on tables including courses and students. 5. Creating tables for a banking database with branches, accounts, customers, loans, and transactions.

Uploaded by

GeehthanJI
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/ 31

GEEHTHAN A/L VINOGOBALAN

S55515

ACTIVITY 1
1&2
3.

4
Database named mypractical is created.

ACTIVITY 2
Data Dictionary
Table 1-Customer
Attribute Description Data Type Size
custID Customer INT -
code
custName Customer VARCHAR 30
Name
custJob Designation VARCHAR 30
custAdd1 Address 1 VARCHAR 30
custAdd2 Address 2 VARCHAR 30
custState State VARCHAR 30
custPostCod Postcode INT 30
e
custContact Contact No. VARCHAR 30

Table 1-Sales
Attribute Description Data Type Size
slsID Sales ID INT -
CustID Customer INT -
ID
slsType Sales type VARCHAR 30
slsOrdDate Sales DATE -
Order Date
slsShipDat Sales Ship DATE -
e Date
Table 3-Product
Attribute Description Data Type Size
prdID Product ID VARCHAR 30
prdName Product VARCHAR 30
Name
prdCategory Product VARCHAR 30
category
prdUnit Product DATE
unit
prpCostPrice Product DECIMAL 25
cost price
prdSalesPric Product DECIMAL 25
e sales price
SQL script.
Customer

Sales
Product

SQL SCRIPT

Table 1 –Customer
Table 2- Sales

Table 3-Product

Activity 3
Srvtechnician table
Output :

Srvcustomer table

Output:
Srvvehicle table

Output

Srvservice table
Output

Srvservicedetails table

Output:
Srvparts table

Output
Activity 4
TASK 1
SQL SCRIPT AND OUTPUT
TASK 2
Output :

After modify , the output is


Student table
Activity 5
1.

2.
3

4.
5.

Different between deleting records and removing the course table .

Deleting records only delete the values that insert in the course table. Meanwhile removing
the course table delete the table from the scheme which means it does not exist.

Lab Exercise
Branch table

Output:
Account table

Output:

Customer table

Output :
Loan table

Output:

Transaction table
Output :
SQL SCRIPTS OF LAB 2
ACTIVITY 2

use mypractical;
CREATE TABLE Table1_Customer
(
custID int ,
custName varchar(30),
custJob varchar(30),
custAdd1 varchar(30),
custAdd2 varchar(30),
custState varchar(30),
custPostCode int,
custContact varchar(30)
);

CREATE TABLE Table2_Sales


(
slsID int ,
custID int,
slsType varchar(30),
slsOrdDate date,
slsShipDate date
);

CREATE TABLE Table3_Product


(
prdID varchar(30),
prdName varchar (30),
prdCategory varchar(30),
prdUnit varchar(30),
prpCostPrice decimal (4,2),
prpSalesPrice decimal (4,2)
);

DESC Table1_Customer;
DESC Table2_Sales;
DESC Table3_Product;

INSERT INTO mypractical .Table1_Customer


VALUES
(10001, 'Ahmad Roslan', 'Insurance Exec','No.15,Jln Air Kolam', 'Kuala Terengganu',
'Terengganu', 21060,'0112563030'),
(10002, 'Chan Liew', 'Bank Officer','No. 1220, Prima Apartment','Mutiara Damansara','Kuala
Lumpur',51200,'0213321919'),
(10003, 'Mohd Sazali','Technician','No.5,Lrg Melati 5/12','Tmn Sri
Gombak','Selangor',48500,'0194451517');

INSERT INTO mypractical.Table2_Sales


VALUES
(21001,10002,'Credit',20160812,20160816),
(21002,10001,'Credit',20160813,20160822),
(31001,10003,'Cash',20160816,20160823);

INSERT INTO mypractical.Table3_Product


VALUES
('PW1001-01','Mach 20/50 Cylinder Oil','Lubricant','Litre',45.00,76.90),
('PW2001-01','Vios Oil Filter','Filter','box',15.35,28.95),
('PW1001-45','Gear Oil 10/30','Lubricant','Litre',28.83, 44.90);

SELECT * FROM Table1_Customer;


SELECT * FROM Table2_Sales;
SELECT * FROM Table3_Product;

ACTIVITY 3
CREATE table srvtechnician
(
tchNo INT(12) ,
tchName varchar(60) NOT NULL,
tchHireDate Date,
constraint pk_srvtechnician primary key(tchNo)
);

CREATE table srvcustomer


(
custCode VARCHAR(15),
custName VARCHAR(60) NOT NULL,
custICNo VARCHAR(15) NOT NULL,
custType VARCHAR(15) NOT NULL,
custAddr VARCHAR(60),
custTown VARCHAR(30),
custPostCode INT(5),
custRegister Date,
PRIMARY KEY(custCode)
);

CREATE table srvvehicle


(
vecNo VARCHAR(10),
vecOwner VARCHAR(15) NOT NULL,
vecChassisNo VARCHAR(30),
vecModel VARCHAR(60) NOT NULL,
vehManufactured VARCHAR(60),
vehYearProduced INT(4),
vehLastOdomoter BIGINT(20),
PRIMARY KEY(vecnO),
FOREIGN KEY(vecOwner) REFERENCES srvcustomer(custCode)
);

CREATE table srvservice


(
srvNo INT(12) ,
custCode VARCHAR(15)NOT NULL,
vecNo VARCHAR(10)NOT NULL,
srvType VARChAR(25) CHECK (srvType in ('Normal','Major','Warranty')),
srvDate DATE,
tchNo INT(5)NOT NULL ,
PRIMARY KEY(srvNo),
FOREIGN KEY(tchNo) REFERENCES srvtechnician(tchNo),
FOREIGN KEY(vecNo) REFERENCES srvvehicle(vecNo),
FOREIGN KEY(custCode) REFERENCES srvcustomer(custCode)
);

CREATE table srvservicedetails


(
srvNo INT(12) NOT NULL,
partNo VARCHAR(45) NOT NULL,
orderQty INT(11)NOT NULL,
slsPrice DECIMAL(9,2),
PRIMARY KEY(srvNo),
FOREIGN KEY(srvNo) REFERENCES srvservice(srvNo),
FOREIGN KEY(partNo) REFERENCES srvparts(partNo)
);

CREATE table srvparts


(
partNo VARCHAR(45),
partDescription VARCHAR(60) NOT NULL,
partCategory VARCHAR(45),
partUnit VARCHAR(35),
partCostPrice DECIMAL(9,2),
partSalesPrice DECIMAL(9,2),
partQtyOnHand INT(11),
PRIMARY KEY(partNo)
);
describe srvtechnician;
describe srvcustomer;
describe srvvehicle;
describe srvservice;
describe srvservicedetails;
describe srvparts;
ACTIVITY 4
TASK 1
use mypractical
ALTER TABLE srvservice
MODIFY custCode VARCHAR(15) NOT NULL;

ALTER TABLE srvservice


MODIFY vecNo VARCHAR(10) NOT NULL;

DESC srvservice;

TASK 2
CREATE TABLE student
(
StudentID VARCHAR(6) primary key,
StuName VARCHAR (50),
Gender CHAR(1) check (Gender in('M','F')),
Program VARCHAR(70),
Intake INT(4)
);
alter table student
modify StuName VARCHAR(10);

DESC student;

INSERT INTO student


VALUES
('S10023','Amran Hamzah','M', 'BSc.Comp. Science (SE)',2014),
('S10023','Goh Seng Huat','M', 'BSc.Comp. Science with IM',2015),
('S30078','Nur Hafizah Rahman','F', 'BSc.Comp. Science (Networking)',2016);

SELECT * FROM student;

ACTIVITY 5
use mypractical;
create table course
(
courseid VARCHAR(10) primary key,
coursename VARCHAR(50)
);
DESC course;

INSERT INTO mypractical.course


VALUES
('CS1001','Programming'),
('CS2001','Advanced Programming'),
('CS3201','Neutral Network');

SELECT* FROM course;

DELETE FROM course WHERE courseid ='CS1001';


DELETE FROM course WHERE courseid ='CS2001';
DELETE FROM course WHERE courseid ='CS3201';

SELECT* FROM course;

drop table course;


SELECT* FROM course;
LAB EXERCISE

use mypractical;

CREATE TABLE Branch


(
branchID INT (25),
branchName VARCHAR (25),
city VARCHAR(25),
branchManager VARCHAR(25)
);

CREATE TABLE Account


(
accNumber INT(25) unique,
icNumber INT(25),
branchID INT(25) primary key,
registerDate date
);

CREATE TABLE Customer


(
icNumber INT(25),
custName VARCHAR(25) not null,
custAddress VARCHAR (100),
town VARCHAR (25),
postcode INT(25),
hpNumber INT(25),
emailID VARCHAR(25),
status VARCHAR(25) default 'New'
);

CREATE TABLE Loan(


loanNumber INT(25),
icNumber INT(25),
loanType VARCHAR(25),
branchID INT(25),
loanAmount INT(100),
loanStatus VARCHAR(25) default 'Apply'
);

CREATE TABLE Transaction(


TransID INT(25),
AccNumber INT (25),
icNumber INT (25),
transactionDate DATE,
transactionTime TIME,
transactionType VARCHAR(25) check (transactionType in('Deposit','Withdrawal')),
transcatioAamount INT(25)
);
DESC Branch;
DESC Account;
DESC Customer;
DESC Loan;
DESC Transaction;

You might also like