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

Daniel

The activity aims to demonstrate basic CRUD (create, read, update, delete) operations in a MySQL database. Students will create two tables, populate them with sample data, and perform queries to view, update and delete records. This allows students to practice fundamental database skills like inserting data into tables, selecting specific fields, and using SQL statements like UPDATE and DELETE.

Uploaded by

Rockers Rock
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Daniel

The activity aims to demonstrate basic CRUD (create, read, update, delete) operations in a MySQL database. Students will create two tables, populate them with sample data, and perform queries to view, update and delete records. This allows students to practice fundamental database skills like inserting data into tables, selecting specific fields, and using SQL statements like UPDATE and DELETE.

Uploaded by

Rockers Rock
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Activity No.

2
CREATE, READ, UPDATE AND DELETE
Course Code: CPE301
Title: DATABASE MANAGEMENT SYSTEMS I
Section: CPE31FC1
Name: Capa , Ryan Onil D.

1. Objective(s):

The activity aims to demonstrate the insertion of content to database, and retrieving data using specific
criteria.

2. Intended Learning Outcomes (ILOs):


The student shall be able to:
2.1 Insert Data to a MySQL Database using Command Line Interface.
2.2 View data using select statements
2.3 Update contents of a database table
2.4 Delete contents of a database table
3. Discussion:

Data Types

A data type or simply type is a classification identifying one of various types of data.

In MySQL, there are three main types of data: Text, Number and Date/Time types.

Data type Description


CHARACTER(n) Character string. Fixed-length n
VARCHAR(n) or Character string. Variable length. Maximum length
CHARACTER VARYING(n) n
BINARY(n) Binary string. Fixed-length n
BOOLEAN Stores TRUE or FALSE values
VARBINARY(n) or Binary string. Variable length. Maximum length n
BINARY VARYING(n)
INTEGER(p) Integer numerical (no decimal). Precision p
SMALLINT Integer numerical (no decimal). Precision 5
INTEGER Integer numerical (no decimal). Precision 10
BIGINT Integer numerical (no decimal). Precision 19
DECIMAL(p,s) Exact numerical, precision p, scale s. Example:
decimal(5,2) is a number that has 3 digits before
the decimal and 2 digits after the decimal
NUMERIC(p,s) Exact numerical, precision p, scale s. (Same as
DECIMAL)
FLOAT(p) Approximate numerical, mantissa precision p. A
floating number in base 10 exponential notation.
The size argument for this type consists of a
single number specifying the minimum precision
REAL Approximate numerical, mantissa precision 7
FLOAT Approximate numerical, mantissa precision 16
DOUBLE PRECISION Approximate numerical, mantissa precision 16
DATE Stores year, month, and day values
TIME Stores hour, minute, and second values
TIMESTAMP Stores year, month, day, hour, minute, and
second values
INTERVAL Composed of a number of integer fields,
representing a period of time, depending on the
type of interval
ARRAY A set-length and ordered collection of elements
MULTISET A variable-length and unordered collection of
elements
XML Stores XML data

Inserting Data to a MySQL table

To insert data into MySQL table, you would need to use SQL INSERT INTO command. Here is generic SQL
syntax of INSERT INTO command to insert data into MySQL table:

INSERT INTO table_name ( field1, field2,...fieldN )

VALUES

( value1, value2,...valueN );

Note that the field1, field2 are attributes in the table. The value1 and value2 are the instances of the
attributes. This indicates that the fields must follow the same order as values.

An alternative way to insert data without using field names is by using this syntax:

INSERT INTO table_name

VALUES

( value1, value2,...valueN );
This shows that the data does not necessarily require an indication of the respective attributes. This
command inserts data to whichever column is present in the database, as long as the data type matches.

Viewing the data present in a database

The SELECT statement is used to select data from a database. The result is stored in a result table, called
the result-set. To select all the data from a particular table, the following syntax can be used:

SELECT *FROM table_name;

The following syntax, on the other hand, selects only the specific columns of the database.

SELECT column_name,column_name FROM table_name;

The SQL UPDATE Statement

The UPDATE statement is used to update existing records in a table. The syntax for this command is as
follows:

UPDATE table_name

SET column1=value1,column2=value2,...

WHERE some_column=some_value;

SQL DELETE Statement

The DELETE statement is used to delete records in a table. The syntax is as follows:

DELETE FROM table_name

WHERE some_column=some_value;

4. Materials and Equipment:


Desktop Computer
Windows Operating System
XAMPP Application

5. Procedure:

1. CREATE DATABASE myDatabase2_<LASTNAME>


2. CREATE table named drivers with attributes:
 ID(int)
 First Name(varchar)
 Last Name(varchar)
 Age(int)
 Address(varchar)
 Vehicle(varchar)
 Years driving (float)
3. Create another table named Vehicles with attributes
 Car Maker(varchar)
 Car Model(varchar)
 Number of Doors(int)
 Car Age (int)
 Weight (15)
4. Populate the tables with at least 5 entries each.
5. Display all the values for each table.
6. Display only the ID, First Name and Last Name the drivers table.
7. Display only the Car Model, Age, and Weight from the Vehicles Table.

6. Data and Results:

TASK COMMAND OBSERVATIONS


Databas
e Create database
Creation Mydatabase2_Capa;
Creating Create table Drivers(ID
Table 1 int, First Name
varchar(255), Last Name
varchar(255), Age int,
Address varchar(255),
Vehicle varchar(255),
Years driving float);

Creating Create table


Table 2 Vehicles(Car Maker
varchar(255),
Car Model varchar(255),
Number of Doors int,
Car Age int,
Weight int (15));

Viewing
Structur Describe drivers;
e of
Table 1

Viewing Describe vehicles;


Structur
e of
Table 2
Inserting Insert into drivers(
a value ID,FirstName,Lastname,
to table1 Age,Address,Vehicle,Yea
rsDriving) Values
('1','Ryan','Capa','22','No
valiches','Toyota','4');

Inserting Insert into


a value vehicles(CarMaker,CarM
to table2 odel,Number Of
Doors,CarAge,Weight)
values
(‘Toyota’,’Xr101’,’4’,’10’,’
4000’);

Selectin Select*from drivers;


g Values
from
table 1

Selectin Select*from vehicles;


g Values
from
table 2
Selectin
g
Specific
Values
from
table 1

Selectin
g
Specific
Values
from
table 2

Questions:

1. What would the database do when two of the same values are inserted at the database?

It will make a same data or short redundancy.

2. Why is it necessary to introduce a WHERE clause when updating and deleting data?

Because “Where” syntax will determine the data to be change.

3. Supposed you input INTEGER data that is intended for VARCHAR. What happens?

It will not not accept letters.


7. Data Analysis:

In this activity I gain a knowledge about adding a data inside the data. I applied also what I learned
in the laboratory. And overall I saw the output of what I ded and its so cool for me.

8. Assessment Rubric:

You might also like