Lecture4 (Lab)
Lecture4 (Lab)
DATABASE MANAGEMENT
SYSTEMS
LAB session 1 Data is in database lets collect it!
Objectives
Introduction to SQL
Introducing the SQL SELECT statement
The DESCRIBE table command
Capabilities of the SELECT statement
Restricting using Where Caluse
The comparison conditions using =, <=, BETWEEN, IN, LIKE, NULL
conditions
Logical conditions using AND, OR, and NOT operators
Single Row Functions
Relational Algebra
Relational algebra is a branch of mathematics and a
formal system used to manipulate and query relational
databases.
It provides a theoretical foundation for the design and
operation of relational database management systems
(RDBMS). Relational algebra operates on relations,
which are represented as tables in a database.
Relations (Tables): In relational algebra, data is
organized into relations, which are represented as
tables with rows and columns. Each row represents a
record, and each column represents an attribute or
field.
Operations: Relational algebra defines a set of operations that can be applied to
relations to perform various tasks such as querying, filtering, combining, and
transforming data. Some common operations include:
Selection: Selects rows from a relation that satisfy a specified condition.
Projection: Selects specific columns from a relation.
Union: Combines two relations to create a new relation containing all the rows from both
relations, removing duplicates.
Intersection: Returns a relation containing only the rows that appear in both input
relations.
Difference: Returns a relation containing only the rows that appear in the first input
relation but not in the second input relation.
Join: Combines two relations based on a common attribute to create a new relation.
Division: Finds all tuples in one relation that match all tuples in another relation.
Closure Property: Relational algebra operations are closed,
meaning that applying any sequence of operations to
relations will always result in another relation. This property
ensures that relational algebra is a powerful and expressive
language for querying and manipulating data.
Formalism: Relational algebra provides a formal and
mathematical foundation for relational database systems,
allowing for rigorous analysis and optimization of queries
and database operations.
SQL
SQL is a commercial interpretation of the
relational algebraic constructs. Three
concepts from relational theory encompass
the capability of the SELECT statement:
Projection
◼ The restriction of columns is called projection.
Selection
◼ The restriction of rows is called Selection
Joining
◼ Interaction of tables with each other is called
joining
SQL
The SQL SELECT statement is mathematically
governed by these three tenets.
An unlimited combination of projections, selections,
and joins provides the language to extract the
relational data required.
Basics of SQL (DML)
List the capabilities of SQL SELECT statements
Execute a basic SELECT statement
Select Statement (conti..)
Select Statement
Using Arithmetic Expressions
Column Alias
AS operator
Concatenation Operator
Give bonus to each person which is 10% of its salary.
..
Task
Create two select queries on employees table.
Create two queries with salary >500 and <1500
Any question!
See you in Next Class !