ITP15 Chapter 1
ITP15 Chapter 1
DATABASE
SYSTEMS
DATABASE CONCEPT
Database
• It is simply a collection of structured data that is organized and stored in a
way that allows easy access, management, and updating. It typically consists of:
o Tables (for relational databases) or other structures (for NoSQL databases
like collections, documents, etc.).
o Data stored in these tables or structures (e.g., rows in a table).
o Types: Relational, NoSQL, Object-oriented, Data Warehouses, Distributed
databases, Document database
o Examples: Relational – MySQL, Microsoft SQL Server, Oracle Database;
NoSQL – MongoDB, Cassandra, Couchbase
• It is managed using specialized software called a Database Management
System (DBMS), which allows users to store, retrieve, and manipulate data
efficiently.
• Its primary role is to store data efficiently and securely.
3
DATABASE CONCEPT
Database Management System (DBMS)
• It is software that helps you interact with the database to perform
operations such as creating, reading, updating, and deleting data.
• It includes a database engine, user interface, and data manipulation
languages.
• It handles tasks like data storage, backup and recovery, security (control
access to the data, user permissions), and data integrity (ensure
consistency)
• Perform queries (via SQL in relational DBMS or other query languages
for NoSQL).
4
DATABASE CONCEPT
Relational Database
• A relational database is a type of database that organizes data into rows
and columns, which collectively form a table where the data points are
related to each other.
• Data is typically structured across multiple tables, which can be joined
together via a primary key or a foreign key.
Table
• It is a collection of related data entries and it consists of columns and
rows.
Record or Row
• It an an individual entry that exists in a table
5
DATABASE CONCEPT
6
DATABASE CONCEPT
Column
• It represents a set of data values of a particular type, one for each row of
the table. For instance, the Student Name column would contain the
names of all students in the Students table.
Field
• It is frequently used in the context of a single record;
• It is the intersection of a row and a column in a table. It contains the
actual value for a specific attribute of a record.
• For instance, in a Student record, the Student Name field could contain
the value “John Doe”.
7
DATABASE CONCEPT
Attribute
• In an Entity-Relationship Diagram (ERD), an attribute is a characteristic or
property that defines an entity in the model. When an ERD is translated
into a physical database model, entities become tables, and attributes
become columns.
8
DATABASE CONCEPT
Attribute
• Within the context of a database, the term attribute can mean any property
that a database object (table, column, schema, trigger, stored procedure,
view, etc.) can possess.
• However, it is most often used to discuss the properties of a table’s column.
1. Name: Every column must have a unique name within its table.
2. Data Type: This defines the kind of data the column can store. It can
be integers, floating-point numbers, strings, dates, Boolean values, or
other types of data depending on the database system.
3. Length or Size: For some data types, such as strings (VARCHAR,
CHAR), you can specify the maximum length.
4. Default Value: You can specify a default value the database system uses
if no value is explicitly provided when a row is inserted.
9
DATABASE CONCEPT
Expressions
• Are combinations of symbols, operators, values, and functions used to perform
calculations, manipulate data, or evaluate conditions. They are a fundamental
part of querying and working with data in a database..
Null Value
• A null value represents the absence of any value. It means that the data is
unknown or missing. It can be assigned to fields of any data type, including
strings, integers, and dates. Importantly, the field is not allocated memory since
NULL signifies an unknown value.
Blank (Empty) Value
• It refers to an empty character or a whitespace character. While its meaning
may seem similar to NULL, it is stored and retrieved like any other character
in a text field. Empty strings are specific to string columns and cannot be
applied to different data types.
11
A NULL value represents the absence of a value or the unknown state of a field. It is
not the same as a blank or empty value. A column value becomes NULL when:
1. No Value is Provided:
When a row is inserted, and a value is not explicitly assigned to a column, it
defaults to NULL (if the column allows NULL values).
• If the Grade column is not specified, its value will be NULL (assuming no
default value is set).
12
An empty value (e.g., an empty string '' for text fields) indicates that a value is present,
but it contains no characters. A column value becomes empty when:
INSERT INTO Students (Student_ID, Name, Grade) VALUES (2, 'Bob', '');
14
• Example: A user leaves a text field blank, and the application saves it as ''
instead of NULL.
DATABASE CONCEPT
Structured Query Language (SQL)
• SQL, or Structured Query Language, is a standardized language used
to manage and manipulate data within relational databases.
• It allows users to perform various operations on data, including
retrieving, inserting, updating, and deleting information.
• SQL is essential for organizing, controlling, and accessing large sets
of structured data in applications ranging from small-scale business
software to large-scale enterprise systems.
16
DATABASE CONCEPT
Projection
• A certain column from a table is selected.
• Controls which columns to display, without filtering rows.
• SQL Keyword: SELECT column_name
Selection
• A subset of rows or records in a table is retrieved once it satisfies a selection
condition.
• Focus: Controls which rows to display, keeping all columns.
• SQL Keyword: WHERE
Joining
• In this operation, data are combined from two or more tables based on one or
more common column values.
• SQL Keyword: JOIN ON
17
CHAPTER 1
RETRIEVING DATA USING THE SQL SELECT
STATEMENT
19
• Example:
SELECT name, description FROM department_list;
21
WHERE CLAUSE
• The WHERE clause is used to filter records. It is used to extract only those records that fulfill a
specified condition.
• Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
• Example:
SELECT *
FROM Employees
WHERE Position = ‘Manager’;
22
GROUP BY CLAUSE
• The GROUP BY Statement in SQL is used to arrange identical data into groups with the help of
some functions. i.e. if a particular column has the same values in different rows then it will
arrange these rows in a group.
• Syntax:
SELECT column1, function_name(column2)
FROM table_name
GROUP BY column1, column2
• Example:
SELECT name, SUM(sal)
FROM emp
GROUP BY name;
23
GROUP BY CLAUSE
GROUP BY CLAUSE
The most commonly used SQL aggregate functions are:
HAVING BY CLAUSE
• Allows the filtering of query results based on aggregate functions and groupings. Unlike the
WHERE clause, which filters individual rows before any grouping occurs, the HAVING clause
works on groups of data that have been aggregated using functions like SUM(), AVG(), COUNT(),
and others.
• The HAVING clause is used to filter the result of GROUP BY based on the specified condition.
The conditions are Boolean type i.e. use of logical operators (AND, OR). This clause was included
in SQL as the WHERE keyword failed when we used it with aggregate expressions.
• Syntax:
SELECT column1, function_name(column2)
FROM table_name
GROUP BY column1, column2
HAVING condition
26
ORDER BY CLAUSE
• The ORDER BY statement in SQL is used to sort the fetched data in either ascending or
descending according to one or more columns.
• SQL ORDER BY default mode is sorting data into ascending order.
• Syntax:
SELECT * FROM table_name ORDER BY column_name ASC | DESC
• Syntax to use ORDER BY Clause with Column Number:
. . . ORDER BY Column_Number asc/desc
Example:
SELECT Roll_no, Name, Address FROM studentinfo ORDER BY 1
ORDER BY 1 means sorting values according to first column in the SELECT statement.
29
LIMIT CLAUSE
• The LIMIT clause allows you to specify the maximum number of records returned by a query. It is
commonly used for limiting query results when only a subset of the data is required, such as for
pagination, filtering top values, or analyzing a smaller portion of a large table.
• MySQL Syntax:
SELECT column_name(s) FROM table_name WHERE condition
LIMIT number;
• SQL/MS Access:
SELECT TOP number|percent column_name(s) FROM table_name
WHERE condition;
• Oracle 12:
SELECT column_name(s) FROM table_name ORDER BY column_name(s)
FETCH FIRST number ROWS ONLY;
32
REFERENCES
• What is a relational database?: https://www.ibm.com/think/topics/relational-databases
• https://advancedsqlpuzzles.com/2023/06/23/attributes-fields-and-columns/
• https://www.geeksforgeeks.org/
• https://www.w3schools.com/
THANK
YOU