Professional Documents
Culture Documents
Introduction
Produces output
Play a critical role in almost all areas where computers are used,
including Business, Engineering, Medicine, Law, Education, And
Library Science, Etc.
The cost and risk during conversion from the old to the new system
Defining database
Constructing database
DBMS.
maintain databases.
These facilities will help the designer, the user as well as the
constraints
04/15/2021 Database System 15
Con’t…
database.
data model
Since the required data or Query by the user will be extracted using
how
04/15/2021 it is to be retrieved
Database System 17
Con’t…
parents.
attributes.
model
Entity - Relationship (E/R) : Views the real world as a set of basic objects (entities)
and relationships among these objects.
Attribute: describes the entity, such as the invoice date or the customer first name.
Eg “EMPLOYEES”(EMPLOYEE1, EMPLOYEE2,
EMPLOYEE3,etc ) entity set represents all the set of employees
Identifiers or
Descriptors.
superkeys.
Alternate key: All the keys which are not primary key are called an
alternate key. It is a candidate key which is currently not the primary
key. However, A table may have single or multiple choices for the
primary key.
Example: In this table. StudID, Roll No, Email are qualified to become
a primary key. But since StudID is the primary key, Roll No, Email
becomes the alternative key.
The Primary key should be selected from the candidate keys. Every
table must have at least a single candidate key.
the composite key may or maybe not a part of the foreign key.
Types of constraints
NOT NULL
UNIQUE
DEFAULT
CHECK
Key Constraints – PRIMARY KEY, FOREIGN KEY
Mapping constraints
Domain constraints
04/15/2021 Database System 2-20
Cont..
NOT NULL: constraint makes sure that a column does not hold NULL
value. When we don’t provide value for a particular column while
inserting a record into a table, it takes NULL value by default.
Key constraints:
Mapping Cardinality:
Domain constraints: Each table has certain set of columns and each
column allows a same type of data, based on its data type. The column
does not accept values of any other data type.
Domain Constraint = data type + Constraints (NOT NULL /
UNIQUE / PRIMARY KEY / FOREIGN KEY / CHECK /
DEFAULT)
The above table is not normalized. We will see the problems that we
face when a table is not normalized.
Conversion to 2NF
A → B:
A is a super key
5. What is ODL ? Explain with neat diagram and compare with E/R.
Unary Operators .
Selection (σ)
Projection (Π)
Rename(ρ)
Binary Operators .
Union (U )
Intersection (˄)
Difference ( – )
The binary operators listed above are also known as set operators.
Unary Operations:
OR
After the renaming the name of the relation and the attributes can be
used as ordinary relation and attributes in a sequence of relational
algebra expressions:
The product operation are maps each tuple in relation with every
tuple in S.
EmpTeams(EmpId, TeamId)
Two relations R(A1, A2, … An) and S(B1, B2, … Bn) are said to be
union compatible if
relations to be joined
EmpTeams(EmpId, TeamId)
Theta Join Operation: While the natural join enforces a join condition
by equating similar attributes in the relations to be joined; a theta join
joins relations to an arbitrary condition C.
Outer Join
Extended Projection
Duplicate Elimination
However, there are cases when we want to have all the tuples from the
participating relations and form the join when there is much. In such
cases outer join operations can be used to keep all the tuples in R, or
all those in S, or all those in both relations irrespective of they having
matching tuples in their common attributes.
Left Outer Join: Keeps every tuples in the left relation R and when
there is no matching for tuples in R from tuples in S, the attributes
of S are filled (padded) with NULL values.
It is denoted by:
It is denoted by:
It is denoted by:
Find the loan number for each loan of an amount greater or equal to
10,000.
Find the names of all customers having a loan at the “ABC” branch.
Formulas in the predicate are build in the same ways as the tuple
calculus predicates.
Table – Relation
Column – Attribute
Row – Tuple
user
Example: create table parent ( pid int not null primary key (id),Pname
char(20) not null )
create table child ( cid int not null primary key, pid int foreign key
references parent(pid) on delete cascade on update cascade
Here, column1, column2, ... are the field names of the table you want
to select data from.
If you want to select all the fields available in the table, use the
following syntax: Select * from table_Name
Eg: SELECT column_name(s)FROM table_nameWHERE condition
GROUP BY column_name(s)HAVING condition
04/15/2021 Database System 5-16
Cont..
The WHERE clause it is a search condition used to filter records.
The WHERE clause is used to extract only those records that fulfill a
specified condition.
SET column1 = value1, column2 = value2, ...
WHERE condition;
04/15/2021 Database System 5-17
Cont..
In SQL aliases are used to give a table, or a column in a table, a
temporary name.
Aliases are often used to make column names more readable and to
avoid ambiguity .
To remove duplicates and have a set of rows as a result one can the
DISTINCT key word on the SELECT clause as follows
There are two wildcards often used in conjunction with the LIKE
operator:
% The percent sign represents zero, one, or multiple characters
_ The underscore represents a single character
The ANY and ALL operators are used with a WHERE or HAVING
clause.
The ANY operator returns true if any of the sub query values meet
the condition.
SELECT column_name(s) FROM table_name
WHERE column_name
operator ANY(SELECT column_name FROM table_name WHER
E condition);
Eg: SELECT ProductName FROM Products
WHERE ProductID= ANY (SELECT ProductID FROM
OrderDetails WHERE Quantity = 10);
04/15/2021 Database System 5-26
Cont..
The ALL operator returns true if all of the sub query values meet
the condition.
Syntax: SELECT column_name(s)FROM table_name
WHERE column_name operator ALL
(SELECT column_name FROM table_name WHERE condition);
OrderDetails WHERE Quantity > 99);
04/15/2021 Database System 5-27
Cont..
The EXISTS operator: is used to test for the existence of any record in
a sub query.
The EXISTS operator returns true if the sub query returns one or more
records.
EXISTS Syntax: SELECT column_name(s) FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);
The BETWEEN operator: selects values within a given range. The
values can be numbers, text, or dates. It is inclusive: begin and end
values are included.
Syntax: SELECT column_name(s) FROM table_name
WHERE column_name BETWEEN value1 AND value2;
SELECT SupplierName FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products
WHERE Products.SupplierID = Suppliers.supplierID AND Price
< 20);
types of join:-
SELECT column_name(s) FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
The query returns all the projects, and if the projects are having teams
the teams will be joined with the teams as well. Projects having more
than one team will be joined with each teams in the resulting table.
Eg2: SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
04/15/2021 Database System 5-37
Cont..
The GROUP BY statement groups rows that have the same values
into summary rows, like "find the number of customers in each
country". Is often used with aggregate functions (COUNT, MAX,
MIN, SUM, AVG) to group the result-set by one or more columns.
A view contains rows and columns, just like a real table. The fields in
a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view
and present the data as if the data were coming from one single table.
Chapter six
Data storage and querying
Primary Storage: Storage media that have direct access to the CPU:
the main memory and the cache. Cache is the lowest level in the
memory hierarchy that is built inside the microprocessor chip.
Typically the response time is in nanoseconds.
The main memory is the next level in the hierarchy that provides the
main working environment for the CPU to keep the programs and
data.
04/15/2021 Database System 6-2
Storage and File Structure
Secondary storage: Storage media for permanent storage such as
magnetic disk and optical disk. Larger in capacity but significantly
slower than the primary storages. Typical response time is in
milliseconds. The secondary storage is used as a virtual memory, disk
storage, and file system.
Tertiary Storage: Storage media that are used for archive and backup
storage data, such as magnetic tape. Typical response time is few
seconds or even in minutes. Virtual memory is storage on the disk that
can is often addressed by 32 bit address space, hence 232~4GB of
data can be managed.
04/15/2021 Database System 6-3