0% found this document useful (0 votes)
59 views

Lab#2

1) The document describes a database activity involving SQL data definition language commands to populate, update, delete and insert data into tables. 2) It involves creating tables for drivers and vehicles, populating them with sample data, updating and deleting rows, and adding a new column to the drivers table. 3) Key tasks covered inserting sample data, displaying table data, updating and deleting rows, adding a new column, and using WHERE clauses to target specific rows for updating and deleting.

Uploaded by

Gelato
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
59 views

Lab#2

1) The document describes a database activity involving SQL data definition language commands to populate, update, delete and insert data into tables. 2) It involves creating tables for drivers and vehicles, populating them with sample data, updating and deleting rows, and adding a new column to the drivers table. 3) Key tasks covered inserting sample data, displaying table data, updating and deleting rows, adding a new column, and using WHERE clauses to target specific rows for updating and deleting.

Uploaded by

Gelato
Copyright
© © All Rights Reserved
You are on page 1/ 9

Activity No.

1 - SQL Data Definition Language Commands


Nepomuceno, Genesi, DL. 3/25/2021
CPE011/CPE21S1 Engr. K. Wong
Database Output:
Database Schema
The image below shows the tables in the database that will be used in this activity. You may use your
previous database from activity 1 or recreate the database to match the structure below.

Part I
1. Use the syntax from the discussion to populate each table with 5 entries each.
drivers
vehicles:

2. Display all the values in each table.

3. Display only the ID, First Name, and Last name of the drivers.
4. Display the car makers and the car models in the vehicles table.

5. Show the screenshot of each set of results with your observation below each in Section 6 Database
Output.
Drivers:

Vehicles:

Part II
1. Use the UPDATE command to change a row value (ex. First Name, age) in each table.

2. Display the values in each table.


3. Show the screenshot of the newly updated tables with your observation below each in Section 6
Database Output.
Drivers:

Vehicles:

Part III
1. Delete one row from each table.

2. Show the screenshot of the newly updated tables with your observation below each in Section 6
Database Output.
Note: Do not drop the database or any tables.
Drivers:

Vehicles:

Part IV
1. Insert two rows to the drivers table with only age and address.

2. Run the command SELECT first_name, last_name FROM drivers;


3. Run the command DELETE FROM drivers WHERE first_name=NULL;
Note: Observe the rows affected if there were rows deleted.

4. Run the command DELETE FROM drivers WHERE first_name is NULL;

5. Run the command SELECT first_name, last_name FROM drivers;

6. Add a new column in drivers called license_number with data type char(13)

7. Run the command DELETE FROM drivers WHERE license_number is NULL;


8. Update one of the rows in the drivers table with a license_number (ex. "N014-123-M01")

9. Run the command SELECT * FROM drivers;

10. Take a screenshot of the code snippets of resulting tables from SELECT commands with your
observation below each in Section 6 Database Output.
SELECT first_name, last_name FROM drivers;

DELETE FROM drivers WHERE first_name=NULL;

DELETE FROM drivers WHERE first_name is NULL;

SELECT first_name, last_name FROM drivers;

DELETE FROM drivers WHERE license_number is NULL;


SELECT * FROM drivers;

Supplementary Activity
Questions
1. What happens if you insert an exact duplicate of any record that is already in your current database
table?
Ex. > INSERT INTO drivers VALUES(1,"James","Nicolas",20,"5 Peace St. QC",3,true);
> INSERT INTO drivers VALUES(1,"James","Nichelistine",20,"5 Peace St. QC",3,true)
You can try the result. Is the output allowable in a real environment? Why do you think the output was what
you saw?
- It duplicates but it is har to manage the database.
2. Given that you ran your SQL Command in the example in Question 1.

What happens if you try to delete one of the rows with the redundant id? (Ex. DELETE FROM drivers
WHERE id=1;) What do you think should the solution be against this kind of problem?
- The data with an id=1 will be deleted.
3. In Part IV of the Procedure section, what do you think is the difference between using an equals sign and
the is keyword when checking for NULL?
- The equal signs needed to use only for the identified value and “is” is for words or phrases.
Additional Reference: https://dev.mysql.com/doc/refman/8.0/en/working-with-null.html
4. Following from the part IV tasks where you’ve added a new column called license_number. What would
happen if you inserted "N014-123-M012XD3"? Why do you think that was the output?
- One of the rows will have "N014-123-M012XD3" in the license_number column.
5. Why is it necessary to introduce a WHERE clause when updating and deleting data?
- It’s because WHERE clause identify the data if it’s needed to be update or delete.

Conclusion:
I conclude in this lab activity that I’ve learned such as how to use UPDATE, DELETE, INSERT INTO,
ALTER, etc.

You might also like