0% found this document useful (0 votes)
5 views34 pages

ITP15 Chapter 1

The document provides an overview of advanced database systems, focusing on database concepts, types, and the role of Database Management Systems (DBMS). It covers relational databases, SQL syntax, and various SQL clauses such as SELECT, WHERE, GROUP BY, HAVING, and ORDER BY. Additionally, it explains attributes, null values, and the importance of structured query language in managing and manipulating data.

Uploaded by

Jojo Bugarin
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)
5 views34 pages

ITP15 Chapter 1

The document provides an overview of advanced database systems, focusing on database concepts, types, and the role of Database Management Systems (DBMS). It covers relational databases, SQL syntax, and various SQL clauses such as SELECT, WHERE, GROUP BY, HAVING, and ORDER BY. Additionally, it explains attributes, null values, and the importance of structured query language in managing and manipulating data.

Uploaded by

Jojo Bugarin
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/ 34

ADVANCED

DATABASE
SYSTEMS

Joy Chrisky V. Lobendino


2

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

5. Constraints: Constraints are rules that the database system enforces.


They include:
o NOT NULL: This means the column must always have a value (it
can’t be NULL).
o UNIQUE: This means all values in the column must be unique.
o PRIMARY KEY: This means the column is the primary key for the
table. Its values uniquely identify each row in the table.
o FOREIGN KEY: This indicates that the column is linked to the
primary key of another table.
o CHECK: This allows you to specify a condition that the values in
the column must meet.
6. Collation: This is a set of rules determining how string data is sorted
and compared. This is relevant for columns that store string data.
7. Auto-Increment: This attribute is available in some database systems. It
automatically generates a unique number for each row, typically used
with a primary key column.
10

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

When Does a Column Value Become NULL?

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).

INSERT INTO Students (Student_ID, Name) VALUES (1, 'Alice’);

• If the Grade column is not specified, its value will be NULL (assuming no
default value is set).
12

2. Explicitly Set to NULL:


When an INSERT or UPDATE statement explicitly assigns NULL to the column.

UPDATE Students SET Grade = NULL WHERE Student_ID = 1;

3. Column Allows NULL:


If the column is defined with NULL allowed (e.g., Grade INT NULL), it can hold
NULL values.
13

When Does a Column Value Become EMPTY?

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:

1. Explicitly Assigned an Empty String:


When an INSERT or UPDATE statement assigns an empty string.

INSERT INTO Students (Student_ID, Name, Grade) VALUES (2, 'Bob', '');
14

2. User Input Results in an Empty String:


If the application layer (e.g., a form or interface) allows saving empty strings as
valid input.

• Example: A user leaves a text field blank, and the application saves it as ''
instead of NULL.

3. No Default Value for a Column:


If a column is set to accept empty strings as valid data and no other value is
provided.

CREATE TABLE Students (


Student_ID INT,
Name VARCHAR(50),
Grade VARCHAR(10) DEFAULT ‘’
);
15

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

SQL CATEGORIES OVERVIEW


• DDL (Data Definition Language) : These are the collection of commands which are required to define
the database.
e.g. CREATE, ALTER, RENAME, TRUNCATE, DROP, etc.
• DQL (Data Query Language) : Retrieves data from tables.
e.g. SELECT
• DML (Data Manipulation Language) : These are the collection of commands which are required to
manipulate the data stored in a database.
e.g UPDATE, INSERT, DELETE, etc.
• DCL (Data Control Language) : These are the collection of commands which are dealt with the user
permissions and controls of the database system.
e.g. GRANT, and REVOKE.
• TCL (Transaction Control Language) : These are the collection of commands which are required to
deal with the transaction of the database.
e.g COMMIT, ROLLBACK, and SAVEPOINT.
18

CHAPTER 1
RETRIEVING DATA USING THE SQL SELECT
STATEMENT
19

SELECT STATEMENT SYNTAX


• The SELECT statement is used to select data from a database.

SELECT [ALL or * | DISTINCT] column1, column2, ...


FROM table_name
[WHERE condition]
[GROUP BY column1, column2, ...]
[HAVING condition]
[ORDER BY column1 [ASC | DESC], column2 [ASC | DESC], ...]
[LIMIT number [OFFSET number]];
20

SELECT AND FROM CLAUSES


• SELECT represents the command to retrieve information from the table
• FROM represents the command to identify where the information to gather will come from.
• Syntax:
SELECT column1, column2, ...
FROM table_name;

SELECT * FROM table_name;

• 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

SELECT Department, sum(Salary) as Salary


FROM Employee
GROUP BY department;
24

GROUP BY CLAUSE
The most commonly used SQL aggregate functions are:

MIN() - returns the smallest value within the selected column


MAX() - returns the largest value within the selected column
COUNT() - returns the number of rows in a set
SUM() - returns the total sum of a numerical column
AVG() - returns the average value of a numerical column
Aggregate functions ignore null values (except for COUNT()).
25

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

Using HAVING to Filter Aggregated Results

SELECT Department, sum(Salary) as Salary FROM Employee GROUP BY department;


27

SELECT Department, sum(Salary) as Salary FROM Employee


GROUP BY department
HAVING Salary >= 70000;
28

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

Example 1 : Sort According To a Single Column using ORDER BY Clause

SELECT * FROM students ORDER BY ROLL_NO DESC;


30

Example 2 : Sort According To Multiple Columns using ORDER BY Clause

SELECT * FROM students ORDER BY age DESC , name ASC;


31

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

SELECT * FROM student LIMIT 3;


33

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

You might also like