(Laboratory No. 3.4: Basic DML SQL 1) : Objectives
(Laboratory No. 3.4: Basic DML SQL 1) : Objectives
(Laboratory No. 3.4: Basic DML SQL 1) : Objectives
1. To store, search and retrieve, and remove records from a database using SQL-DML commands
Materials:
1. PC or Laptop
2. WAMP/XAMPP Installer
3. Web Browser or CLI
Background
DML- 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. Below are the commands:
1. INSERT
2. SELECT
3. UPDATE
4. DELETE
Instructions:
1. Create a database with a name following the format <your last name>_activityBasicDML1
Example: BASTE_ActivityBasicDML1.
2. Using your previous database in previous activity which you were able to backup, you can import it right
here. Otherwise, you can simply create a new database file and table.
Do the following instruction and provide a screenshot (or paste in a notepad) for each action you performed.
a. If you have the following table definition, here’s how you do it.
SQL / Output
b. By using SELECT command, you are able to display the records containing in the tbl_pet table.
As you wish, invoke the following statement:
SQL / Output
c. What if you want to insert 2 or more than rows or records? Here’s how.
INSERT INTO tbl_pet values (2, ‘Lee Tsu Non’,’male’, 15), (3, ‘Kelly Cally’,’female’, 16);
SQL / Output
Or if you want to store only specific value or fields to your table, you do this:
INSERT INTO tbl_pet (pet_id, pet_name, pet_age) values (2, ‘Anne ann’, 12);
SQL / Output
SQL / Output
e. Now, show the records of your tbl_pet table using SELECT command.
SQL / Output
NOTE: You will observe that you are able to store records having the same IDs even if they
have different information. Hence, it is called data duplications and it must be avoided. For
now, let us leave it as it is. We will have another activity intended for that purpose.
f. You just tried removing tbl_buyer table from your previous using DROP command. This time I
want you to use TRUNCATE TABLE command. To do it see below:
SQL / Output
NOTE: You will observe that all of the records of your table tbl_pet is now gone but NOT the
tbl_pet. Unlike when you use DROP command, the table all of its records are all eradiated
from the database. For your information DROP and TRUNCATE commands are belonged to
DDL SQL.
DB Programmer’s tasks:
1. Using your tbl_owner table, store these values: 1,” Cain”, “Davao City”, “female”, 2229614.
Your table should become:
SQL / Output
2. Show records of your tbl_owner table using SELECT statement. Invoke the SQL statement below to
accomplish the task:
SELECT *from tbl_owner;
You should have shown like this:
SQL / Output
SQL / Output
4. Insert information for tbl_pet atleast 5 of your own specifications and preference.
SQL / Output
SQL / Output
NOTE: Observe that you are able to store information of pet having the same Pet_id since it wasn’t
specified as primary key. Hence, duplication is possible.
SQL / Output
SQL / Output
8. Insert information to your table tbl_owner atleast 3 of your own specifications and preference.
SQL / Output
SQL / Output
SQL / Output
Congratulations! You have just made your first database application. To summarize, you have encountered
some basic SQL statements. The first part was about creating database, tables, describing and specifying its
structures. Some of the commands are CREATE, ALTER, DROP, RENAME, SHOW, DESCRIBE which belongs
significantly to DDL or Data Definition Language. On the other hand, we have DML or Data
Manipulation Language which you are taught to store information to a table using INSERT and display this
information using SELECT statement. Some of the SQL commands under DML are DELETE and UPDATE.