Vous êtes sur la page 1sur 4

College of Computing Education

3rd Floor, DPT Building


Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

Name :_______________________________ Date :__________________________________


Time :_______________________________ Prof :_______________________________

[ Laboratory No. 3.5: Basic DML SQL 2]


Objectives:

1. To know the difference between SQL-DDL DROP and TRUNCATE


2. To know more about SQL commands under DML such as Insert, Update, Delete and Select.

Materials:

1. PC or Laptop
2. WAMP/XAMPP Installer
3. Web Browser or CLI

Background

DDL includes commands such as CREATE, ALTER and DROP statements is used to CREATE, ALTER OR DROP
the database objects (Table, Views, Users).

 DROP - delete objects from the database


 TRUNCATE - remove all records from a table, including all spaces allocated for the records are
removed

Data Manipulation Language (DML) statements are used for managing data within schema objects DML
deals with data manipulation, and therefore includes most common SQL statements such SELECT, INSERT,
etc. DML allows to add / modify / delete data itself.

DML is used to manipulate with the existing data in the database objects (insert, select, update, delete).

DML Commands:

1. INSERT
2. SELECT
3. UPDATE
4. DELETE

*INSERT:
Syntax: INSERT INTO Table name values();

*SELECT:
Syntax: Select*from <table name>

*UPDATE:
Syntax: Update<table name> set to(calculation);

*DELETE:
Syntax: Delete form<table name>

CCE104/L Martzel P. Baste|Page 1


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

Instructions:

Using your previous activity having tbl_pet and tbl_owner tables, do the following instruction and provide a
screenshot (or paste in a notepad) for each action you performed. Kindly follow naming conventions for
your activity.

-------------------------------------------------Objective 1-------------------------------------------------
1. Show your database tables.
SQL /OUTPUT

2. Add new table using existing table. This can be used to backup or duplicate a table to your database.
Do this,

Creating new table without removing the existing table:

CREATE table tbl_pet_new Select *from tbl_pet;


SQL /OUTPUT

Creating new table by removing the existing table:

CREATE table tbl_pet_new_DROP Select *from tbl_pet;


SQL /OUTPUT

NOTE: This will copy the data and the structure, but not the indexes.

3. Add new table to duplicate tbl_pet. This time name it tbl_pet_backup_truncate.


SQL /OUTPUT

4. Show fields or describe the tbl_pet_backup_drop and tbl_pet_backup_truncate.


SQL /OUTPUT

5. Show records of the tbl_pet_backup_drop and tbl_pet_backup_truncate


SQL /OUTPUT

CCE104/L Martzel P. Baste|Page 2


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

6. Remove the tbl_pet_backup_drop from your database using DROP. Here’s how you do it.

DROP table tbl_backup_drop;

SQL /OUTPUT

7. Remove the tbl_pet_backup_truncate using TRUNCATE. Here’s how you do it.

TRUNCATE table tbl_backup_truncate;

SQL /OUTPUT

8. Show tables of your database. Write your observations in the box provided.

9. Show records of your tbl_backup_truncate. Write your observations in the box provided.

10. Remove tbl_backup_truncate from your database.

SQL /OUTPUT

CCE104/L Martzel P. Baste|Page 3


College of Computing Education
3rd Floor, DPT Building
Matina Campus, Davao City
Telefax: (082)
Phone No.: (082)300-5456/305-0647 Local 116

---------------------------------------------Objective 2---------------------------------------------
11. Store additional 5 records to your tbl_pet.

SQL /OUTPUT

12. Perform the following SQL command:


o UPDATE tbl_pet set pet_name=’Lucia’
o SELECT *from tbl_pet

SQL /OUTPUT

Observations:

o UPDATE tbl_pet set pet_name=’Digong’ where pet_gender=’male’


o SELECT *from tbl_pet

SQL /OUTPUT

Observations:

13. Remove all records whose pet’s name is Lucia.


14. Store additional 3 information to your tbl_pet with the same pet_id which is 1.
15. Change one of the pet’s name to ‘Luh Bee’ which pet’s id is 5.
16. Change one of your pet’s id to 10 to any of your pets having pet_id of 1.
17. Remove any of your pet whose id’s are the same. Make sure to leave 1 item or pet of that id.
18. Fill-in desired information to all of your pets having null values.
19. Fill-in desired information to all of your owners having null values.
20. Show records of the two tables.
21. Type the word “slurppp” in the comment section during submission.

CCE104/L Martzel P. Baste|Page 4

Vous aimerez peut-être aussi