0% found this document useful (0 votes)
9 views9 pages

Cir 106 Lab Manual - Update 2

This document is a lab manual for a Database Systems course at Maseno University, detailing various MySQL programming tasks. It includes step-by-step instructions for opening the MySQL environment, creating databases and tables, inserting and querying data, and managing records. The manual covers practical exercises for students to gain hands-on experience with database management and SQL commands.

Uploaded by

goldieprinco018
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)
9 views9 pages

Cir 106 Lab Manual - Update 2

This document is a lab manual for a Database Systems course at Maseno University, detailing various MySQL programming tasks. It includes step-by-step instructions for opening the MySQL environment, creating databases and tables, inserting and querying data, and managing records. The manual covers practical exercises for students to gain hands-on experience with database management and SQL commands.

Uploaded by

goldieprinco018
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/ 9

MASENO UNIVERSITY

BACHELOR OF SCIENCE IN COMPUTER SCIENCE

BACHELOR OF SCIENCE IN COMPUTER TECHNOLOGY

BACHELOR OF SCIENCE IN MATHEMATICS AND

COMPUTER SCIENCE

BACHELOR OF EDUCATION SCIENCE WITH IT

YEAR 1 SEMESTER 2

CIR 106: DATABASE SYSTEMS

LAB MANUAL

1
Read MySQL programming pdf notes I sent you.

LAB 1A: Opening MySQL DBMS Programming Environment


1. Click search text field at the task bar then type MySQL.
2. Click MySQL Command line client from the pop up window on the desktop.
3. You will get a black window with a phrase” Enter password ” written at the top right corner
4. Type (press) Enter key.
5. Mysql> prompt will appear on the black window.
6. You will start writing SQL statement at the prompt.

LAB 1B: Interogating databases in the Server


1. Open MySQL Command line client
2. Type Show databases; at the prompt then press enter key.
3. The system will give you a list of the databases in the server.

LAB 1C: Creating a database


1. From the command prompt, type: create database year1sem2;
2. Type: Show databases;
3. You should see year1sem2 in the list of databases presented by the server.

LAB 1D: Creating a table in a particular database


In order to create a table in a particular database, e.g year1sem2, you must make that database a current
database as follows:
1. Type: use year1sem2;
2. Type: select database();
3. You will see year1sem2 database appearing as the default database.
4. Any table that is created will be stored in the current database.

LAB 1E: Creating a product table in year1sem2 database


1. At the command prompt type the following:
Create table product
(
productID int unsigned not null,

2
productCode char(3) not null default ‘ ‘ ,

name varchar(30) not null default ‘ ‘ ,

quantity int unsigned not null default 0,

price decimal(7,2) not null default 99999.99,

Primary key (productID)

);

2. Type: show tables;


3. Type: Describe product;

LAB 1E: Placing data in a table


1. Type the following code to place ten records in the product table:
Insert into product
Values (101, ‘com’ , ‘computer’ , 20, 45000.55),
(102, ‘pri’ , ‘printer’ , 10, 35000.40),
(103, ‘mos’ , ‘mouse’ , 40, 100.20),
(104, ‘tab’ , ‘table’ , 20, 20000.25),
(105, ‘pap’ , ‘paper’ , 30, 600.60),
(106, ‘ups’ , ‘power supply’ , 30, 25000.45),
(107, ‘mak’ , ‘marker pen’ , 100, 85.25),
(108, ‘era’ , ‘eraser’ , 30, 150.85),
(109, ‘ink’ , ‘ink’ , 40, 250.15),
(110, ‘mon’ , ‘monitor’ , 15, 600.755) ;

LAB 1F: Viewing all data in a database table


1. To view all data in product table
2. Type: Select * From product;

LAB 1G: Viewing Selected data in a database table


1. To view selected data in product table
2. Type:
Select * From product
Where productID >104;

3
LAB 2A: Adding more data in a database table
 Add ten more records of your choice in the product table

LAB 2B: Viewing all data in a database table


1. To view all data in product table
2. Type: Select * From product;

LAB 2C: Deleting a record from a database table


1. To view all data in product table
2. Type:
Delete From product
Where productID = 120 ;
3. Type: Select * From product ; to confirm that the record is actually deleted

LAB 2D: Ordering the selected records from a table in


ascending order
1. Type:
Select * From product
Order by name asc ;

LAB 2E: Ordering the selected records from a table in


ascending order
1. Type:
Select * From product
Order by productID desc ;

LAB 2F: Creating supplier table


 Type:
Use year1sem2 ;
Create table supplier
(
supplierID int unsigned not null,
name varchar(30) not null,

4
phone varchar(15) not null,
primary key (supplierID)
);

LAB 2G: Adding records to supplier table


1. Type:
Insert into supplier values
( 800, ‘ Paul Ouma‘ , ‘0722999312 ‘),
( 801, ‘ Rose Njeri‘ , ‘0715999316 ‘),
( 802, ‘ Vera Nyabuto‘ , ‘0721999317 ‘),
( 803, ‘ Hasan Abdi‘ , ‘0733949310 ‘),
( 804, ‘ Dan Omari‘ , ‘0111999311 ‘),
( 805, ‘ Caroline Chebet‘ , ‘0712499312 ‘);
2. Type:
Select * from supplier;

LAB 2H: Adding a field called city to supplier table


1. Type:

Alter table supplier


Add column city varchar(20) not null ;

LAB 2I: Adding values to city field of supplier table


 Use the correct command to add appropriate values of city to each supplier.
 Type: Select * from supplier; to view the values in supplier table.

LAB 2J: Adding a field called supplierID to product table


1. Type:

Alter table product


Add column supplierID int unsigned not null ;

5
LAB 2K: Adding values to supplierID field of product table
1. Type:
Update product set supplierID = 102;
2. This command sets the entire column of supplierID in product table to be 102

LAB 2L: Adding foreign key constrain to supplierID of


product table
1. Type:

Alter table product


Add Foreign key (supplierID) references supplier (supplierID) ;

LAB 2M: Updating supplierID in the product table


 Update product table such that each supplier can supplier about 4 items

LAB 3A: Creating unit table


 Type:
Use year1sem2 ;
Create table unit
(
unitCode varchar(30) not null,
name varchar(50) not null,
primary key (unitCode)
);

LAB 3B: Creating student table


 Type:
Create table student
(
regNumber varchar(20) not null,
name varchar(30) not null,
gender varchar(6) not null,
DOB Date not null,
Phone varchar(15) not null,
primary key (unitCode)
6
);

LAB 3C: Placing records in unit table


 Type:
Insert into unit values
(‘CIR 106’ , ‘Database Systems’),
(‘CIR 102’ , ‘Descrete Structures II’),
(‘CIR 104’ , ‘Object Oriented Programming I’),
(‘CIR 108’ , ‘Systems Analysis and Design’),
(‘MMA 116’ , ‘Linear Agebra I’),
(‘MAS 102’ , ‘Probability and Statistics Theory I’),
(‘CCS 122’ , ‘Electronics’),
(‘PHT 112’ , ‘HIV and AID Determinants prevention and Management’),
(‘CCT 102’ , ‘ Engineering Mathematics II’),
(‘CCT 118’ , ‘ Digital Electronics I’),
(‘CCT 116’ , ‘ Digital Electronics I Lab’);

 Type:
Select * From unit ; to view the data entered,

LAB 3D: Placing records in student table


 Type:
Insert into student values
(‘CCS/00001’ , ‘Jane Nyabuto’ , ‘Female’ , ‘2004-10-04’ , ‘0722990425’ ),
(‘CCS/00002’ , ‘Paul Ouma’ , ‘Male’ , ‘2001-10-04’ , ‘0712990420’ ),
(‘CCS/00003’ , ‘Jane Nyabuto’ , ‘Female’ , ‘2003-10-04’ , ‘0732990461’ ),
(‘CCS/00004’ , ‘Hasan Abdi’ , ‘Male’ , ‘2000-10-04’ , ‘0742990428’ ),
(‘CCT/00001’ , ‘Caroline Njeri’ , ‘Female’ , ‘2004-11-04’ , ‘0752990420’ ),
(‘CCT/00002’ , ‘Hasan Abdi’ , ‘Male’ , ‘2002-02-04’ , ‘0742990428’ ),
(‘TMC/00003’ , ‘Ken Lotodo’ , ‘Male’ , ‘2000-02-04’ , ‘0742990421’ ),
(‘TMC/00004’ , ‘Rose Wanjala’ , ‘Female’ , ‘2004-02-04’ , ‘0742994428’ ),
(‘ESC/00003’ , ‘Dan Ojijo’ , ‘Male’ , ‘2001-02-01’ , ‘0782990427’ ),
(‘ESC/00004’ , ‘Vera Mwania’ , ‘Female’ , ‘2003-08-24’ , ‘0792994426’ ),
(‘ESN/00003’ , ‘Frank Sitera’ , ‘Male’ , ‘2004-07-15’ , ‘0112990460’ ),
(‘ESN/00004’ , ‘Vera Mwania’ , ‘Female’ , ‘2003-12-04’ , ‘055994455’ ),

7
 Type:
Select * From student ; To view data entered into student tables.

LAB 3E: Creating student_unit table


 This demonstrates many to many relationship between student and unit table.
 Type:
Create table student_unit
(
regNumber varchar(20) not null,
unitCode varchar(30) not null,
primary key (regNumber, unitCode),
Foreign key (regNumber) references student (regNumber),
Foreign key (unitCode) references unit (unitCode)
);

LAB 3E: Placing records in student_unit table


 Use appropriate commands to place and view 20 records in student_unit table.

LAB 3F: Adding Age field in student table


 Type:
Alter table student
ADD column Age int unsigned not null;
 Desc student;

LAB 3G: Placing values to Age field in student table


 Type:
Update student
Set Age = YEAR(CURDATE()) - YEAR(DOB);

8
 Type:
Select * From student ; to view the content of student table after placing values of Age field.

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