GORDON COLLEGE
College of Computer Studies
ITC122A/L – INFORMATION MANAGEMENT 1
LABORATORY ACTIVITY NO. 3
TITLE: SQL DATABASE, TABLES AND QUERIES
NAME: Kirk Arem Adal Date:2-9-19
Course & Block: BSIT – 1D Score: _____________
OBJECTIVE:
The objective of this lab exercise is to provide you with the ability to create your own database. After completing this
lab exercise, you will be able to:
● Design and implement a database.
● Choose and assign right datatypes.
● Write SQL Queries and practice using MySQL client.
● Use SQL Statements to retrieve data from Database.
INSTRUCTION:
Write your answer queries in the space provided for checking.
Part I. DATABASE AND TABLE
1. Create a Database named ‘company_db’.
Create database company_db;
2. Use the database you’ve created.
Use company_db;
3. Check if you have correctly selected the database.
Select database();
4. Create a table named ‘manufacturer’ with the following table structure:
Create table manufacturer
(Code int(11) not null,
Name varchar(1) not null,
Primary key(Code));
5. Display the table’s structure to verify if it is similar to the structure above.
Describe manufacturer;
Page 1 of 4
GORDON COLLEGE
College of Computer Studies
6. Create another table named ‘product’ with the following table structure:
Create table product
(id int(11) null,
name varchar(255) not null,
price decimal(10,2) not null,
manufacturer int(11) not null);
7. Show the tables you’ve created.
Show tables;
8. In ‘manufacturer’ table, alter the table to add another field ‘country’ and set the data type with varchar(40) that will
not accept null values.
Alter table manufacturer
Add country varchar(40) not null;
9. In ‘manufacturer’ table, alter the table to modify the data type limit of ‘name’, change the limit to varchar(50).
Alter table manufacturer
Modify Name varchar(50);
10. Change the name of the ‘product’ table to ‘products’.
Alter table product
Rename to products;
11. In ‘product’ table, change the field name ‘name’ to ‘prod_name’ with the same data type and limit.
Alter table products
Page 2 of 4
GORDON COLLEGE
College of Computer Studies
Change name prod_name varchar(255);
12. Display the table structure of the two updated tables.
Describe products,manufacturer;
Part II. SQL QUERIES , INSERT AND SELECT
13. Insert the following data into manufacturer table:
Insert into manufacturer
(Code,Name,country)
Values
(1,’Sony’,’Japan’),
(2,’Creative Studio’,’Canada’),
(3,’Hewlett Packard’,’US’);
14. Select/Display all of the columns and data in manufacturer table to verify.
Select * from manufacturer;
15. Insert the following data into products table:
Insert into products
(id,prod_name,price,manufacturer)
Values
(1,’Hard drive’,240.50,1),
(2,’Memory’,320.60,2),
Page 3 of 4
GORDON COLLEGE
College of Computer Studies
(3,’CPU’,480.60,3);
16. In manufacturer table, select the Name and Country column and retrieve all the data rows.
Select name, country from manufacturer;
17. In manufacturer table, select all of the columns where the Country is equal to Japan.
Select * from manufacturer where country=’Japan’;
18. In products table, select prod_name and price where the manufacturer is equal to 3.
Select prod_name, price from products where manufacturer=3;
19. In products table, select all of the columns where the price is less than Php 330.00.
Select * from products where price<330.00;
20. In products table, select the prod_name and sort it in descending order by prod_name.
Select prod_name from products
Order by prod_name desc;
Bonus question hugot line:
Buti pa yung products may halaga, ako walang halaga sa kanya hahahahahahahah wag minus sir
Prepared by:
Jet Renz R. Ferrer
Instructor I
CCS Department
Page 4 of 4