0% found this document useful (0 votes)
21 views51 pages

Module in CC104 Information Management PDF

The CC-104: Information Management module is designed for 2nd year BS Information Technology students at Nueva Ecija University, focusing on the fundamentals of Information Management and database programming using SQL. It covers essential topics such as the DIKAR model, data versus information, database systems, data modeling, and the characteristics of relational databases. The module aims to equip students with the necessary skills to understand and utilize database management systems effectively.

Uploaded by

kashimohajime31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views51 pages

Module in CC104 Information Management PDF

The CC-104: Information Management module is designed for 2nd year BS Information Technology students at Nueva Ecija University, focusing on the fundamentals of Information Management and database programming using SQL. It covers essential topics such as the DIKAR model, data versus information, database systems, data modeling, and the characteristics of relational databases. The module aims to equip students with the necessary skills to understand and utilize database management systems effectively.

Uploaded by

kashimohajime31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

1

The module in CC-104: Information Management is a


collaborative effort of the subject teachers from the
College of Information and Communications Technology.
This is intended for the 2nd year BS Information
Technology of the Nueva Ecija University of Science and
Technology.

This instructional material's objective is to allow the


students to learn the components of Information
Management and its importance in our day-to-day
lives. This module provides a strong foundation about
information management system concepts and basic
database programming using Structured Query Language
(SQL). Students or the beginner in the database
environment who will use this module can easily
understand the database's principles, the importance of
data modeling, the power of using a relational database,
and the easiest way to execute some basic SQL command
using MySQL.

The Authors

2
UNIT I
INTRODUCTION TO INFORMATION MANAGEMENT AND DATABASES 5
Data versus Information 5
Information Management 6
DIKAR Model 7
Evolution of File System and Data Processing 7
File System Problems 8
The Role of a Database 9
File Systems vs Database Systems 10
The Database System Environment 10
Types of Databases 11
Database Management System 12
DBMS Advantages 12
DBMS Functions 13

UNIT II DATA MODELS 15


Data Modeling and Data Models 15
Data Model 15
Problem Domain 16
The Importance of Data Models 16
Types of Database Models 16
Features of a Relational Database Model 19
Entity Relationship Diagram (ERD) 20
ERD Components 20
Basic Cardinalities 21
Three ways to do ERD 22
Degree of Relationships 23
Business Rules 24
Business Rules Translation 24

3
UNIT III RELATIONAL MODEL CHARACTERISTICS 26
Relational Database Model 26
Characteristics of a Relational Table 26
Integrity Rules and Keys 27
Relational Schema 28
Data Dictionary and System Catalogs 29
Relational Set Operators 29
Codd’s Relational Database Rules 30

UNIT IV Structured Query Language (SQL) 32


Two Categories of SQL Functions 32
Common SQL Data Types 33
Basic SQL Commands – Part 1 33
Create Database 33
Use Database 34
Create Table 34
Alter Table 35
Insert Values 36
Updating a Specific Row 37
Basic SQL Commands – Part 2 38
SELECT 38
WHERE 39
AND, OR, NOT 40
IN 42
BETWEEN 42
LIKE 43
ORDER BY 44
Basic SQL Commands – Part 3 45
Deleting 45
Aggregate Functions 45
Constraints 48

References 51

4
UNIT I

INTRODUCTION TO INFORMATION MANAGEMENT AND DATABASES

LEARNING OBJECTIVES

At the end of this chapter, the students should be able to:

1. Identify the importance of database


2. Differentiate data from information
3. Identify the different database approach
4. Differentiate manual file systems from computerized file systems
5. Identify the main components of the database system
6. Explain the main functions of a database management

LESSON PROPER

Data versus Information

Sound decisions require valid information. And such information is derived from
the observable facts around us.

Source: https://computersciencewiki.org/images/b/b1/Databases_2.pdf

5
Data- refers to raw facts that we can collect about entities- people, objects, and events.
Information- refers to processed data – which gives meaning to the raw facts.
Knowledge - relevant and objective information that helps in drawing conclusions.

Source: https://computersciencewiki.org/images/b/b1/Databases_2.pdf

Information Management
Choo (1995) defined information management (IM) as the management of
processes and systems responsible for acquiring, creating, organizing, distributing, and
using information.

In his discussion about Information Management, there are six related activities
involved in IM:

1. Identification of information needs


2. Acquisition and creation of information
3. Analysis and interpretation of information
4. Organization and storage of information
5. Information access and dissemination
6. Information use and archiving

Importance: IM is about ensuring that information is available to the right person, in


the right format at the right time.

6
DIKAR Model

One of the associated models in information management is the DIKAR model.


This model shows the transition of raw facts into information; then, from information,
knowledge can be derived. And from the knowledge, we can identify the action needed
to achieve the desired results. Knowing this model helps organizations identify the
technology needs to assist in the efficient transformation of data for their business
needs.

Data
Information
Knowledge
Action
Result

Evolution of File System and Data Processing

Two systems can be utilized in Information Management: file systems and


database systems.

Before going straight to databases, it is essential to learn first the concept of the
file system. Knowing file systems can be helpful to understand the complexities of
databases and the conversion to database systems.

File systems can either manual or computerized. The manual file system is the
traditional pen-paper-folder file management. It is composed of a collection of file
folders, categorized and stored in cabinets.

The computerized file system uses computers and storage devices to acquire,
organize, and store data. It also facilitates faster data tracking and report generation as
compared to the manual method.

7
File System Problems

1. Dependence in structural and data changes

Structural dependence happens when changes in the file structure will entail
modifications in related programs and files to roll-out or apply the new structure.
Structural independence is when changes in file structures do not affect data
access.

File structure changes include: adding of fields, changing of file types.

Data dependence happens when data structure changes affect data access. Data
independence is when these changes do not affect the data nor the related
programs.

Data structure changes include: change in keys, change in data types.

2. Data Redundancy

File systems are prone to data redundancy due to having data from multiple
resources and do not have automatic measures to avoid multiple data copies. If
redundancy exists, it can result in having:

• Poor data security

As multiple copies exist, it is difficult to track changes and ensure user


roles. Thus, unauthorized access will be challenging to manage and most
likely to happen.

• Data inconsistency

This happens when multiple copies of the data have conflicting versions.
This is usually a result of a particular update done in one document but
failed to update other existing copies.

8
• Lack of data integrity

The existence of data redundancies might compromise data integrity.


Integrity is defined as the consistency and accuracy of data.

3. Lack of design structure and models

File systems usually lack design and data models as compared to database
systems. Data models contribute to the overall structure and logic flow that
enable databases to be more organized in managing data.

4. Exposure to various data anomalies

Anomaly means an abnormality, an error, or an inconsistency. Types of data


anomalies are as follow:

• Update anomaly - happens when an update done results in data


inconsistency or discrepancy.

• Insertion anomaly - happens when inserting a new record might result in


incomplete information or failure to insert due to dependence on other
attributes.

• Deletion anomaly - happens when deleting a record might result in loss


of data or information.

The Role of a Database

As the data collected evolves and the transactions being done in businesses,
innovation and improvement in storage have been a continuous necessity for a
business. Hence, apart from file systems, database systems are often the more viable
option for organizations.

A database is a centralized collection of end-user data and metadata. End-user


data are facts derived from the system users, such as the ones retrieved from

9
transactions. Metadata is often described as data about data or information about the
database and tables' structure and components.

A database helps in transforming retrieved data into useful information. Through


a database management system, databases can facilitate adding, updating, retrieving,
and deleting data.

File Systems vs Database Systems

Source: Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,
Implementation, and Management, Ninth Edition 2015

The Database System Environment

A database system environment is comprised of five components:

• Hardware – the physical devices

10
• Software – the applications necessary to run a database. This includes the
operating system, database management system, among others.
• People – includes all the system stakeholders: end-users, designers,
administrators, programmers, and analysts.

• Procedures – the policies or system rules.

• Data – raw facts collected.

Types of Databases

1. Based on the number of users:

• Single user database supports one user at a given time.

• Workgroup database is intended for a group of users. One example is one


department.

• Enterprise database supports multiple groups of users working together and


accessing files simultaneously, such as organizations and corporations.

2. Based on location:

• Centralized database is located and maintained at a single site.

• Distributed database is distributed across several different sites and servers.

3. Based on data stored:

• General-purpose database usually includes a wide range of topics and/or


types of documents.

• Discipline-specific database focuses on a single academic discipline or a


group of related fields.

11
4. Based on the how it will be used and the time sensitivity of information:

• Operational database stores and supports real-time business data.

• Analytical database contains historical data that can be used for business
intelligence.

5. Based on the degree which the data are structured:

• Relational database is used to handle structured data.


o Structured data – are easily searchable by algorithms

• Non-relational database (NoSQL) is for handling unstructured data.


o Unstructured data – have no predefined structure.

Database Management System

Coronel et al. (2015) defined database management system (DBMS) as a system


used to create and manage databases and facilitates the organization, manipulation,
and retrieval of data.

DBMS Advantages

1. Improved data sharing

DBMS is capable of providing a platform for the users to access more organized
data.

2. Improved data security

DBMS is capable of improving data security and privacy by providing facilities for
managing access levels and implementing security policies.

12
3. Better data integration

Since data sharing and access are enhanced, DBMS can help the management
have a clearer view of how their business segments are doing.

4. Minimized data inconsistency

Well-designed databases can minimize the occurrence of having multiple copies


of data that results in inconsistencies. DBMS can help in the implementation of
primary and foreign keys that enforce integrity.

5. Improved data access

DBMS can facilitate quick responses for data retrieval requests making it easier to
search and find what you need.

6. Improved decision making

It is easier to study the data and make strategic reports through a more
organized and faster retrieval of data.

7. Increased end-user productivity

By providing ease of access and data availability, DBMS can help users do their
work faster and more efficiently.

DBMS Functions

1. Data dictionary management

A data dictionary holds the metadata about the database structures. DBMS offers
features that help manage and generate data dictionaries for reference and
documentation purposes.

13
2. Data storage management

Database performance can be fine-tuned to be more efficient in the storage and


retrieval of information.

3. Data presentation

DBMS can aid in the acquisition, storage, and transformation of data presented in
a structured way to satisfy logical expectations.

4. Security management and multi-access control

Access roles and levels can be configured through an Access Control List (ACL),
which allows the limited rights and privileges per user type.

5. Back-up and recovery management

Back-up and recovery options are available to avoid database outages and data
loss.

6. Data integrity management

Integrity is the consistency and accuracy of data. Through the enforcement of


the integrity rules, DBMS is capable of ensuring data integrity.

7. Database application and communication interfaces

DBMS can handle the Structured Query Language (SQL) and its connection with
other programming languages and applications. Also, it supports communication
with other databases.

14
UNIT II

DATA MODELS

LEARNING OBJECTIVES

At the end of this chapter, the students should be able to:

▪ Explain data modeling


▪ Recognize the importance of data models
▪ Define the business rules and explain the influence in designing a database
▪ Explain the evolution of data models
▪ Design data models and identify basic cardinalities based on given business rules.

LESSON PROPER

Data Modeling and Data Models

Database design primarily focuses on the processing and handling of end-user

data using the database structure. In developing a database, the first phase is data
modeling, which refers to creating a data model for a given problem domain.

Data Model

A data model is a visual representation of a real-world data structure. It displays


data representation and how the data can be accessed.

15
The various features, changes, and constructs on a particular database based on a
domain and collection of business rules or specifications are illustrated using a data
model.

Problem Domain

It is a defined collection of scope and boundaries based on a real-world area or


situation projected to be solved.

The Importance of Data Models

1. It facilitates interaction between the designer, the application programmer, and


the end-user.

2. It allows a better understanding of a particular organization for which the


database is intended to be built.

3. It serves as the database’s blueprint.

Types of Database Models

1. Flat File Model

It is a database model that utilizes a single table design. It may have many fields
that are prone to data inconsistency, redundancy, and corruption. You can use
the copy and paste method to copy data from different flat files, and automation
is not allowed. Delimiters like tabs and commas are used to separate files in the
record.

16
Source: https://www.researchgate.net/figure/Example-of-a-Flat
File_fig1_291448084

2. Hierarchical Model

The data is stored organized in a tree-like structure, and records are


interconnected through links. The data can be retrieved by traversing the whole
tree starting from the root.

Source:Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,


Implementation, and Management, Ninth Edition 2015

17
3. Network Model

The network model is known for its flexible way of representing data. The
structure follows a graph format where objects are nodes and relationships are
arcs.

Source: Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,
Implementation, and Management, Ninth Edition 2015

4. Object-Oriented Model

The object-oriented model envisions entities as objects. Each object has


attributes (state) and methods (behavior). An object belongs to a single class
only and as its instance.

Source: Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,
Implementation, and Management, Ninth Edition 2015

18
5. Relational Model

The relational model views a database as a set of tables with columns and rows.
Each table represents an entity or a data source. Each row is an instance of that
entity. Keys uniquely identify such rows. And each column is the attribute or
property of the entity.

Source: Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,
Implementation, and Management, Ninth Edition 2015

Features of a Relational Database Model

• Rows and columns can be in any order.

• Every row is unique so that there is a specific value in each row that is different
from the value in the other row.

• A field can only contain one value.

• Values under a column of fields are from a similar domain.

• Table names and so as its column names must be unique.

19
Entity Relationship Diagram (ERD)

Entity Relationship Diagram is a modeling technique to represent the database


components and the relationships between entities.

ERD Components

1. Entity

• person, place, thing, or event that we want to store information about

• denoted by a NOUN

• represented by a rectangle shape in the ERD

2. Relationship

• describes the relationship between two entities

• denoted by a VERB (passive or active)

• represented by a diamond shape In the ERD

3. Attribute

• data collected about the entities

• represented by an oval shape in the ERD

20
4. Cardinalities

• the number of times an instance of an entity can relate to instances of


other entities

• often symbolized by the crow's foot notation

Basic Cardinalities

Other Symbols/Notations:

Zero or one (optional)

Zero or many (optional)

Examples:

21
Three ways to do ERD

Source: Adapted from https://quizlet.com/237169032/chapter-2-data-models-10-25-


2017-diagram/

Source:Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,


Implementation, and Management, Ninth Edition 2015

22
Degree of Relationships

The degree of a relationship is based on the entities that are related to each
other. There are three types of degree and these are as follow:

• Unary Relationship – when the relationship that exists is within the same entity.

• Binary Relationship – when a relationship exists between two different entities.

• Ternary Relationship – when three entities share a relationship.

23
Business Rules

A business rule is a specific description of a company's policy or procedure. It


states how an organization does things in terms of its transactions and operations.
These rules are used in the identification of the entities, attributes, relationships, and
constraints.

Examples: Each student can register for one or more classes.

Each class can have many students.

Each teacher can only handle a maximum of 30 students.

Bi-directional: Each employee works in one store. Each store has many
employees.

Each engineer borrows one or more gadgets. Each gadget is


borrowed by one engineer.

Business Rules Translation

Translating business rules into database components requires analysis and


understanding. Here are some tips to spot the significant components easily.
24
• A noun in a business rule is a possible entity.

Example:

Business rule: Each student can register for one or more classes.

Entities: Student and Class

• A verb that associates the nouns is a possible relationship.

Example:

Business rule: Each student can register for one or more classes.

Entities: Student and Class

Relationship: registers

To determine the relationship type by asking"how many" questions. In the


example above, you can ask:

1. How many classes can a student register for? Many

2. How many students can a class have? Many

• Additional information about an entity is the attributes.

Examples:

Student attributes: student_name, student_id, student_course

Class attributes: class_code, class_name, class_adviser

25
UNIT III

RELATIONAL MODEL CHARACTERISTICS

LEARNING OBJECTIVES

At the end of this chapter, the students should be able to:

• Discuss relational database model(RDM) that offers a logical view of data


• Identify the model's basic components.
• Construct logical relations that composed of a unique set of rows and distinct
columns
• Explain relational database(RD) operators, the data dictionary, and the system
catalog
• Discuss data redundancy in the model
• Discuss Codd’s 12 Rules for Relational Databases

LESSON PROPER

Relational Database Model (RDM) – is presented as data tables that collect groups of
elements into relations. These models work based on the idea that each table setup will
include a primary key or identifier. Relations are represented by tables.

Characteristics of a Relational Table

1. A table is a relation that is expressed as a set of related columns and rows.

2. Each table row is called a tuple representing a single instance of an entity within a
set.

3. An attribute is represented by the table's column and should have a unique name
or identifier in the table.

26
4. A single data value is represented in each point where the row and column meet.

5. The attribute domain defines the valid values for the columns.

6. The placements of each row and column or their orders in relation to each other
are of no consequence in a database's definition or identity.

7. Each row should have a unique combination of values and its attributes
compared to other rows in the table.

Integrity Rules and Keys

There are two main types of integrity that can be enforced in a table:

• Entity Integrity – Usually implemented by creating primary keys for each row
in the table that is unique from all other rows.

• Referential Integrity – the condition in which every reference to an entity's


instance by another instance is valid.

Key – it consists of a group of attributes that can be used as a basis for getting other
attributes in the row.

1. Primary Key

• It is the attribute that is used to differentiate each row in a table.

• Responsible for entity integrity.

• Requirements:
o the value must be different from all other values for that attribute;
unique

o the value null cannot be used for an attribute to be used as a key

27
2. Foreign Key

• It forms a relationship by placing a primary from one table to another table.

• It enforces referential integrity.

• It is safeguards the tables from actions that would discredit links between
tables.

• It ensures that the valuess being entered in the foreign key column is valid
and exists in the table it points to.

Relational Schema

A schema is a logical grouping of database objects related to one another and


becomes a guide on how the database is constructed.

Simple Schema Example

28
Data Dictionary and System Catalogs

A data dictionary is a comprehensive account of metadata about the tables –


such as table names, the fields inside and their data types, relationships, and extra
information are stored. This also part of the system documentation for easier reference.

A system catalog is more detailed and greater in scope as it can include database
details and all objects in the database.

Example of a Data Dictionary

Table: Student

Field name Data Type Limit Required Others


s_id VARCHAR 10 Yes Primary key, format:
Campus-Year-Control
number
s_name VARCHAR 70 Yes
s_course VARCHAR 10 Yes
s_bday DATE n/a Yes MM-DD-YY format

Relational Set Operators

1. SELECT – this command will produce the selected values of attributes for every
row that is true for a set of specified conditions.

2. PROJECT – this command will show all values of the selected fields/attributes.

3. UNION – this command will show the union of two tables (A and B). The
duplicates of A+B will not be shown. A + B – ( A ∩ B) = A U B

4. INTERSECT – this command will show the rows in which A and B intersect or are
the same. A ∩ B

5. DIFFERENCE – this command will show the rows in two tables that only appear in
one table and do not appear in the other. A U B – (A ∩ B)

29
6. PRODUCT – produces all combinations of rows from two tables (A and B) where
the first part of the row is from table A and the second part is table B.

7. JOIN – this command combines rows from two tables that have shared values on
a selected attribute

8. DIVIDE – this command takes two tables, one two-column table, and one one-
column table. The latter table acts as a divisor to the former.

Codd’s Relational Database Rules

E. F. Codd invented and formalized the concept of the relational database in 1970
at IBM. According to his idea, a relational database contains several relations, with
tuples represented mostly as rows related in many ways.

Moreover, a relational database is composed of rows where each row satisfies the
integrity constraints. Such that any operation done on the rows does not violate the
integrity constraints.

Dr. E. F. Codd also defined 12 rules that a relational database system should
always follow. These rules help ensure that the database design will be free of or at
least minimized anomalies.

Let’s revisit the three anomalies introduced in the previous topic usually
encountered in file and database systems. These anomalies are classified as:

• Update anomalies – inconsistencies that might happen when we do an


update in a record.

• Insertion anomalies – inconsistencies or action failure when adding a record

• Deletion anomalies – inconsistencies that might occur when removing a


record.

30
Having a well-structured and well-designed database can eliminate or minimize
occurrences of such anomalies. Dr. Codd’s 12 rules for relational databases can provide
useful guidelines in creating a sound relational database design. For each rule and its
description, we can refer to the figure below.

Source: Carlos Coronel, Steve Morris, Peter Rob, Database Systems: Design,
Implementation, and Management, Ninth Edition 2015

31
UNIT IV

Structured Query Language (SQL)

LEARNING OBJECTIVES

At the end of this chapter, the students should be able to:

• Describe the basic commands and functions of SQL.


• Use SQL statements in creating, updating, and deleting databases and tables.
• Use SQL aggregate functions in problem-solving.
• Integrate the database concepts learned into a project concept.
• Create models and incorporate SQL based on given case/business rules.

LESSON PROPER

Structured Query Language (SQL)

According to Coronel et al. (2015), SQL is a standardized language used in relational


databases.

Two Categories of SQL Functions

1. Data Definition Language (DDL)

SQL includes commands to create database objects such as tables, indexes, and
views and commands to define access rights to those database objects.

Examples: CREATE DATABASE, CREATE TABLE, ALTER TABLE, DROP TABLE,


PRIMARY KEY, FOREIGN KEY

32
2. Data Manipulation Language

SQL includes commands to insert, update, delete, and retrieve data within the
database tables.

Examples: INSERT, UPDATE, DELETE, SELECT, COMMIT, ROLLBACK

Common SQL Data Types

Basic SQL Statements – Part 1


Note: SQL commands are not case sensitive.

1. Creating Database

Example:
If you want to create a database named DBCLASS, the command will be:
CREATE DATABASE DBCLASS;

33
2. Use Database – it is essential to set which database will be the default.
Whichever is set as default will be the database that the commands will pertain or
be performed to.

Example:
To make the newly created database the default database:

USE DBCLASS;

3. Create Table – the column parameter refers to the attributes, while the data type
parameter refers to the type of values each column can hold.

Example:
If we want to add a new table called tblstudent with attributes s_id, s_fname,
s_mname,s_lname, s_section, s_age - the code will be:

CREATE TABLE tblstudent(


s_id INT,
s_fname VARCHAR(50),
s_mname VARCHAR(50),
s_lname VARCHAR(50),
s_section VARCHAR(5),
s_age INT
);

34
4. Alter Table – in case you needed to change something in the table (add/edit
columns)

Syntax for adding a column:

Example:
If we want to add s_bday column to tblstudent, the code will be:

ALTER TABLE tblstudent


ADD COLUMN s_bday VARCHAR(10);

Syntax for modifying a column (changing data types of columns):

Example:
Suppose we need to update the data type of s_bday to DATE, the code will be
something like this:

ALTER TABLE tblstudent


MODIFY COLUMN s_bday DATE;

Syntax for changing a column (changing names of columns) :

35
Example:
Suppose we need to change the column name, s_bday to s_birthday, the code
will be:

ALTER TABLE tblstudent


CHANGE s_bday s_birthday DATE;

Syntax for deleting a column:

NOTE: If you do this, all data stored in this column will be deleted as well.

Example:
If we want to delete the column, s_age, the code will be:
ALTER TABLE tblstudent
DROP COLUMN s_age;

5. Insert Values

Example:
From the examples we did above, our final table structure for tblstudent is:

s_id s_fname s_mname s_lname s_section s_birthday

36
To insert value using Syntax1:
INSERT INTO tblstudent(s_id, s_fname, s_mname, s_lname, s_section, s_birthday)
VALUES(20090001, 'Juan', 'Mabini', 'Dela Cruz', '2W', '1990-03-14');

Example: Alternatively, we can use syntax 2:


INSERT INTO tblstudent
VALUES(20090002, 'Maria', 'Mabini', 'Clara', '2W', '1990-04-11');

So now, the table will be:

6. Updating a specific table row

Example:
If we want to correct Maria's middle name to "Santos," the code will be:

UPDATE tblstudent
SET s_mname = 'Santos'
WHERE s_id = 20090002;

37
The table has been updated. And tblstudent now looks like this:

Basic SQL Commands – Part 2


Note: SQL commands are not case sensitive.

For all examples, assume we have the table named tblstudent with the following
contents:

1. SELECT – is used to search and display the result.

Syntax to retrieve and display everything that is in the table:

EXAMPLE:

SELECT * FROM tblstudent;

OUTPUT:

38
Syntax to retrieve only the contents of specific column/columns:

EXAMPLE:

SELECT s_id FROM tblstudent;

OUTPUT:

Note: if you want to display data from multiple columns, separate the column
names by a comma.

EXAMPLE:

SELECT s_id, s_section FROM tblstudent;

OUTPUT:

2. WHERE – is added to specific SQL commands to filter records based on a given


condition. The WHERE clause accepts different operators such as =, >, >=, <, <=,
<>, IN, LIKE, BETWEEN.

39
EXAMPLES:
SELECT * FROM tblstudent
WHERE s_lname = 'Dela Cruz';

OUTPUT:

SELECT s_id, s_fname FROM tblstudent


WHERE s_lname = 'Dela Cruz';

OUTPUT:

3. AND, OR, NOT – these can be combined with the WHERE clause to filter data
using more than one condition.

AND will display a record only if all the conditions joined by the AND operator
are TRUE.

OR will display a record if at least one of the conditions joined by the OR


operator is TRUE.

NOT will display a record if the condition is NOT TRUE.

40
EXAMPLE:

SELECT * FROM tblstudent


WHERE s_id = 20090001 AND s_section = '2W';

OUTPUT:

EXAMPLE:

SELECT * FROM tblstudent


WHERE s_id = 20090001 OR s_section = '2W';

OUTPUT:

EXAMPLE:

SELECT * FROM tblstudent


WHERE NOT s_id = 20090001;

41
OUTPUT:

4. IN – is used when you need to include multiple values of a column in the WHERE
clause.

EXAMPLE:

SELECT * FROM tblstudent


WHERE s_id IN (20090001, 20090003);

OUTPUT: Note that only the record of Juan was retrieved since the table has no
s_id 20090003

5. BETWEEN – get the values within a given range. The values can be numbers, text,
or dates.

EXAMPLE:

SELECT * FROM tblstudent


WHERE s_birthday BETWEEN '1990-01-01' AND '1990-03-31';

42
OUTPUT:

6. LIKE –used for searching specific data patterns.

EXAMPLES:

SELECT s_fname FROM tblstudent


WHERE s_fname LIKE '%A';

OUTPUT:

SELECT s_fname FROM tblstudent


WHERE s_fname LIKE 'J%';

OUTPUT:

43
7. ORDER BY – is used to display the data in an ascending or descending order.

EXAMPLES:

SELECT * FROM tblstudent


ORDER BY s_birthday ASC;

OUTPUT:

SELECT * FROM tblstudent


ORDER BY s_birthday DESC;

OUTPUT:

44
Basic SQL Commands – Part 3
Note: SQL commands are not case sensitive.

1. DELETING

2. AGGREGATE FUNCTIONS – methods that can be utilized for calculations

Basic functions:
a. AVG() –for averaging

Example: Assuming a table called tblproduct has a column price:

45
b. SUM() –computes for the sum of the data stored in the specified column.

c. MIN() – returns the column’s lowest value.

Example: Using the table tblproduct:

46
d. MAX() - returns the column’s highest value.

Example: Using the table tblproduct:

e. COUNT() - returns the number of records returned by a select query.

Example: Using the table tblproduct:

47
3. CONSTRAINTS – These can be used to identify the primary key, foreign key, and
which values should not accept null and duplicates.

Syntax for NOT NULL AND UNIQUE:

EXAMPLE:

Syntax for PRIMARY AND FOREIGN KEYS:

48
EXAMPLE :Assume we have this diagram:

Notes:

• During the table creation, add cust_id in the product table to have a column
created for it.

• The cust_id data type in the product table should match the data type of the
cust_id in the customer table.

• Then, declare it as a foreign key. The “REFERENCES” part is where you define
the original table it belongs to.

49
50
References:

Coronel, Carlos et al. (2015) Database Principles of Fundamentals of Design,


Implementation and Management 10th Edition, Cengage Learning

Bensi, Leonyln P. (2016) Database Management System 1 Worktext. Nueva Ecija


University of Science and Technology

Pratt, Philip and Last, Mary. (2011). A Complete Guide to MYSQL. Cengage Learning

Venkatraman, N., 1996. Managing IT Resources as a Value Center. IS Executive Seminar


Series, Cranfield School of Management

Chun Wei Choo. Information Management FAQ. http://choo.ischool.utoronto.ca/IMfaq/

Queensland Government Chief Information Office


https://www.qgcio.qld.gov.au/information-on/Information-Management/how-should-i-
manage-my-information/why-is-information-management-so-important

Tech Difference. Differences Between Data and Metadata.


https://techdifferences.com/difference-between-data-and-metadata.html

SQL Tutorial – w3schools (https.//www.w3schools.com/sql/)

Additional Images Sources:

https://computersciencewiki.org/images/b/b1/Databases_2.pdf

https://www.researchgate.net/figure/Example-of-a-Flat

https://quizlet.com/237169032/chapter-2-data-models-10-25-2017-diagram/

https://www.tlu.ee/~sirvir/Information%20and%20Knowledge%20Management/Key_Conc
epts_of_IKM/information_management.html

https://keydifferences.com/difference-between-information-and-knowledge.html

https://www.smartdraw.com/entity-relationship-diagram/

51

You might also like