Chapter 1 Introductionn
Chapter 1 Introductionn
and
Database Management Systems
2
Basic Definitions
• Database:
– A collection of related data.
• Data:
– Known facts that can be recorded and have an implicit meaning.
• Mini-world:
– Some part of the real world about which data is stored in a
database. For example, student grades and transcripts at a
university.
• Database Management System (DBMS):
– A software package/system to facilitate the creation and
maintenance of a computerized database.
• Database system:
– The DBMS software together with the data itself. Sometimes, the
applications are also included.
5
Database
• Shared collection – can be used simultaneously
by many departments and users.
• Logically related - comprises the important
objects and the relationships between these
objects.
• Description of the data – the system catalog
(meta-data) provides description of data to
enable data independence.
6
What Is a Database?
An organised, machine-readable collection
of symbols, to be interpreted as a true
account of some enterprise.
Machine-updatable, too …
… so a database is also a collection of variables.
• Banks
• HRM
• Stock Management
– Supermarket
• Library Systems
• Universities
• ETC
17
File Based Systems vs Database System
20
Database application program
21
Database Management Systems
• A
Examples:
database is a collection of information
• A– database
Oracle management system (DBMS) is the software
– DB2
that (IBM)Database
manage
– MS SQL Server
– MS Access
– Ingres
– PostgreSQL
– MySQL
• and more
Now, how does a relational DBMS do these things? …
27/10/2024 Fundamental of Database System By 25
Dagne w
Why use a DBMS?
• Why use a DBMS? OS provides RAM and
disk
– Concurrency
– Recovery
– Abstraction, Data Independence
– Query Languages
– Efficiency (for most tasks)
– Security
– Data Integrity
Fundamental of Database System By Dagne w
27/10/2024 26
Data Administration
• Used for:
– Backup and recovery
– Security
– Change management
• Create, read, update, and delete (CRUD)
• Database administrator (DBA)
– Individual or department
– Responsibilities
27/10/2024 Fundamental of Database System By 27
Dagne w
Database Users
• Users may be divided into
– Those who actually use and control the
database content, and those who design,
develop and maintain database applications
(called “Actors on the Scene”), and
– Those who design and develop the DBMS
software and related tools, and the computer
systems operators (called “Workers Behind the
Scene”).
27/10/2024 Fundamental of Database System By Slide 1- 28
Dagne w
Database Users
• Actors on the Scene
– Database administrators
• Responsible for authorizing access to the database,
for coordinating and monitoring its use, acquiring
software and hardware resources, controlling its use
and monitoring efficiency of operations.
– Database designers
• Responsible to define the content, the structure, the
constraints, and functions or transactions against the
database. They must communicate with the end-
users and understand their needs.
27/10/2024 Fundamental of Database System By Slide 1- 29
Dagne w
Database End Users
• Actors on the scene
• End-users: They use the data for queries, reports
and some of them update the database content.
End-users can be categorized into:
• Casual: access database occasionally when needed
• Naïve or parametric: they make up a large section of
the end-user population.
– They use previously well-defined functions in the form of
“canned transactions” against the database.
– Users of mobile apps mostly fall in this category
– Bank-tellers or reservation clerks are parametric users
who do this activity for an entire shift of operations.
– Social media users post and read information from
websites
27/10/2024 Fundamental of Database System By Slide 1- 30
Dagne w
Database Users
• System analysts and application developers
– System analysts: They understand the user requirements
of naïve and sophisticated users and design applications
including canned transactions to meet those requirements.
– Application programmers: Implement the specifications
developed by analysts and test and debug them before
deployment.
– Business analysts: There is an increasing need for such
people who can analyze vast amounts of business data and
real-time data (“Big Data”) for better decision making
related to planning, advertising, marketing etc.
• Traditional applications:
– Numeric and textual databases
• More recent applications:
– Multimedia databases
– Geographic Information Systems (GIS)
– Biological and genome databases
– Data warehouses
– Mobile databases
– Real-time and active databases
39
Components of DBMS
Environment
• Hardware
– Can range from a PC to a network of
computers.
• Software
– DBMS, operating system, network software (if
necessary) and also the application programs.
• Data
– Used by the organization and a description of
this data called the schema.
40
Components of DBMS
Environment
• Procedures
– Instructions and rules that should
be applied to the design and use
of the database and DBMS.
• People
– Includes database designers,
DBAs, application programmers,
and end-users.
41
Functions of a DBMS
• Data Storage, Retrieval, and Update.
• A User-Accessible Catalog.
• Transaction Support.
• Concurrency Control Services.
• Recovery Services.
42
Functions of a DBMS
• Authorization Services.
• Support for Data Communication.
• Integrity Services.
• Services to Promote Data Independence.
• Utility Services.
43
Advantages of DBMSs
• Control of data redundancy
• Data consistency
• Sharing of data
• Improved data integrity
• Improved maintenance through
data independence.
44
Disadvantages of
DBMSs
• Complexity
• Cost of DBMS
• Cost of conversion
• Performance
• Higher impact of a failure
45
Data Models
• DBMS models real world
• Data Model is link between user’s
view of the world and bits stored
in computer
• Many models exist
• We will concentrate on the Student(sid:Students(sid: string, name: string,
Relational Model login: string, age: integer, gpa:real)
10101
11101
46
Fundamental of Database System By
Dagne w
Data Model
• Integrated collection of
concepts for describing data,
relationships between data,
and constraints on the data.
• Has three components:
– a structural part;
– a manipulative part;
– a set of integrity rules.
47
Implementation of Data
Models
– Hierarchical
– Network
– Relational
48
1. Hierarchical Database Model
• Logically represented by an upside down tree
– Each parent can have many children
– Each child has only one parent
49
Sample Database of Hierarchical
model
50
Hierarchical Database Model
• Advantages
– Conceptual simplicity
– Database security and integrity
– Data independence
– Efficiency
• Disadvantages
– Complex implementation
– Difficult to manage and lack of standards
– Lacks structural independence
– Applications programming and use complexity
– Implementation limitations
51
2. Network Database Model
• Each record can have multiple parents
– Composed of sets
– Each set has owner record and member record
– Member may have several owners
Figure
1.10 52
Network Database Model
• Advantages
– Conceptual simplicity
– Handles more relationship types
– Data access flexibility
– Promotes database integrity
– Data independence
– Conformance to standards
• Disadvantages
– System complexity
– Lack of structural independence
53
3. Relational Database Model
54
A simplified architecture for a database system
• UPDATE <name>
SET <field name> = <value>
WHERE <condition>
• SELECT <fields>
FROM <name>
WHERE <condition>
27/10/2024 Fundamental of Database System By 67
Dagne w
Creating Relations in SQL
• Creates the Students relation. CREATE TABLE Students
(sid CHAR(20),
• Note: the type (domain) of each name CHAR(20),
login CHAR(10),
field is specified, and enforced age INTEGER,
by the DBMS gpa FLOAT)
DELETE
FROM Students S
WHERE S.name = ‘Smith’
Powerful variants of these commands are availabl
more later! Fundamental of Database System By
Dagne w 69
27/10/2024
Adding and Deleting Tuples
• Can insert a single tuple using:
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (53699, 'Green ', 'green@ee', 18, 3.5)
More inserts:
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (53666, 'Jones', 'jones@cs', 18, 3.4)
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (53688, 'Smith ', 'smith@eecs', 18, 3.2)
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (53650, 'Smith ', 'smith@math', 19, 3.8)
81
Views
• Benefits include:
– Provide a level of security;
– Provide a mechanism to customize the
appearance of the database;
– Present a consistent, unchanging
picture of the structure of the
database, even if the underlying
database is changed.
82
Views
• A view is just a relation, but we store a
definition, rather than a set of tuples.
CREATE VIEW YoungActiveStudents (name, grade)
AS SELECT S.name, E.grade
FROM Students S, Enrolled E
WHERE S.sid = E.sid and S.age<21
S.name E.cid
we get:
Smith Topology112
27/10/2024 Fundamental of Database System By 85
Dagne w
Stages of the database system
development lifecycle
86
Database planning
• Management activities that allow stages of
database system development lifecycle to be
realized as efficiently and effectively as possible.
• Should be integrated with overall IT strategy of
the organization
• development of standards that govern:
– how data will be collected,
– how the format should be specified,
– what necessary documentation will be needed,
– how design and implementation should proceed
87
System definition
organization’s information
Requirements
collection and
analysis
• Process of collecting and
analyzing information about
the organization to be
supported by the database
system, and using this
information to identify the
requirements for the new
system.
89
Requirements
collection and
analysis
• Information is gathered for
each major user view including:
– a description of data used or
generated;
– details of how data is to be
used/generated;
– any additional requirements for
new database system.
90
Requirements
collection and
analysis
• Information is analyzed to identify requirements
for new database system.
• Another important activity is deciding how to
manage database system with multiple user views.
• Three main approaches:
– centralized approach;
– view integration approach;
– combination of both approaches.
91
Database design
94
Guidelines for
form/report design
95
Prototyping
• Building working model of a
database system.
• Purpose
– to identify features of a system that
work well, or are inadequate;
– to suggest improvements or even
new features;
– to clarify the users’ requirements;
– to evaluate feasibility of a particular
system design. 96
Implementation
97
Data conversion and
loading
• Transferring any existing data into
new database and converting any
existing applications to run on
new database.
– only required when a new database system is
replacing an old system.
– common for a DBMS to have a utility that loads
existing files into the new database.
– May be possible to convert and use application
programs from the old system for use by the new
system. 98
Testing
• Process of running the database
system with the intent of finding
errors.
– Use carefully planned test strategies
and realistic data.
– Testing cannot show absence of
faults; it can show only that
software faults are present.
– Demonstrates that database and
application programs appear to be99
working according to requirements.
Operational
maintenance
• Process of monitoring and
maintaining the database system
following installation and
involves:
– monitoring performance of system. If
performance falls, may require
tuning or reorganization of the
database.
– maintaining and upgrading database
system (when required). 100
– incorporating new requirements into
?
Thank you!
101
SQL Questions
1.What is Database Software?
The software is used for doing DBMS/RDBMS activities is called database. RDBMS
( Relational Database Management System). Relationships between the database Objects.
DBMS:-
Ex: MS-Access, D-Base, FoxPro etc...
RDBMS:-
Ex: Oracle, MS-SQL Server, IBM DB2, MySQL (free source), Sybase, Teradata etc....
2.Types of SQL Commands?
• DROP: -- Drops the structure & data of table using drop table tablename;
• TRUNCATE: -- Removes the all the rows permanently using truncate table tablename;
• DELETE: -- Removes the all the rows temporarily. We can Roll back the rows.
delete from table;
7.Difference between Truncate Vs Delete queries?
Truncate Delete
Delete all records from table. Delete all records from table or
delete specific records from table
by using condition
Not able to ‘Rollback’ because Able to ‘Rollback’ because ‘delete’ is
truncate is DDL DML[Data Manipulation Language]
[Data Definition Language]
Truncate locks entire table during Delete locks corresponding rows
operations. during operation.
Ex:-
Ex:-
Truncate table students;
Delete all rows from table Delete from students where Sid=001;
delete rows, which rows Sid is 001
8.Define Union, Union all, Minus and Interact ?
g
10.What is Self Join?
To join two tables, we need a common column in two tables as foreign key to join a table
with it self, we need two columns with similar data in that table
Select * from table1 innerjoin table1 on column1=column2;
Above like quires result is equal to select distinct queries result.
11.Types of Sub-queries?
SQL can provide TCL commands like commit & Rollback to handle transactions. While
using this commands, we need to follow below rules:
Rull1:- Off auto commit in My-SQL server because My-SQL server can auto commit transactions
by default.
Set autocommit=0; set autocommit=off;
Rull 2:- We need to start transaction
start transaction;
Rull 3:- Perform required manipulations [insert, update, delete]
Rull 4:- Do commit or Rollback for current transaction.
14.Types of Functions in SQL?
While preparing select queries, we can use various building functions in SQL.
Aggregate Functions
Comparison Functions
String Functions
Math Functions
Date and Time Functions
Control flow Functions
Miscellaneous Functions
15.What is Aggregate Functions?
SQL Aggregate Functions calculates values from multiple columns in a table and
returns a single value.
AVG(), SUM(), MAX(), MIN(), MAX(), COUNT()
• SELECT AVG(SALARY) FROM EMPLOYEES;
• SELECT SUM(SALARY) FROM EMPLOYEES;
• SELECT MIN(SALARY) FROM EMPLOYEES;
• SELECT MAX(SALARY) FROM EMPLOYEES;
• SELECT COUNT(*) FROM EMPLOYEES;
16.Permanent Table Vs Temporary table Vs Derived table?
Permanent Table
A table which is stored permanently database until drop is called as permanent table we can use
below query.
Create table tablename(column name datatype constraint, multiple columns……….);
Temporary table
SQL Languages can allow as creating temporary tables in database. A temporary table
is created by using create temporary table statement. My-SQL removes the temporary table
automatically when the session ands or the connection is terminated.
Create temporary table table_name select * from original_table;
Derived table
SQL can allow as to create derived table. A derived table is a virtual table returned from a select
statement. A derived is similar to a temporary query execution only where as
temporary table can alive until session ends or the connection is terminated.
Derived_table_name where derived table_name c1>0;
17.What is the Primary key and Foreign keys?
Primary key
A Primary key is a column whose values uniquely identify every row in a
table. Primary key values can never be reused.
Foreign keys
When a one table’s primary key field is added to related tables in order to
create the common field which relates the two tables, it called a foreign key in other
tables. Foreign Key constraints enforce referential integrity.
18.Explain Having & Order by clause
Having clause: Having clause is used to filter the output from the group by clause.
Select department_id, sum(salary) from employees where department_id<>50
group by department_id;
Select department_id, sum(salary) from employees
group by department_id having sum(salary)>20000;
Order By clause: Order by clause is used to arrange the rows in a table (ascending or
descending order).
select * from employees order by department_id desc;
select * from employees order by salary;
19.What is Read lock?
The only session that holds the lock of a table can read & write data from the table
other sessions cannot read data from and write data to the table until the write lock is released.
If the session is terminated, either normally or abnormally, My-SQL will release all the write
locks implicitly.
Auto increment keyword allows the user to create a unique number to get
generated whenever a new record is inserted into the table. This keyword is usually
required whenever PRIMARY KEY is used.
Single-column Indexes: A single-column index is created for only one column of a table.
Syntax:CREATE INDEX index_nameON table_name(column_name);
Composite-column Indexes:
A composite-column index is an index created for two or more columns of the table.
Syntax:CREATE INDEX index_name ON table_name (column1, column2)
Unique Indexes: Unique indexes are used for maintaining the data integrity of the table. They don’t allow
multiple values to be inserted into the table.
Syntax: CREATE UNIQUE INDEX index ON table_name(column_name)
24.What is Denormalization in a Database?
Denormalization is used to access the data from higher or lower normal form of database. It
also processes redundancy into a table by incorporating data from the related tables. Denormali-
zation adds required redundant term into the tables so that we can avoid using complex joins and
many other complex operations. Denormalization doesn?t mean that normalization will not be
done, but the denormalization process takes place after the normalization process.
25.What is the use of the Intersect operator?
The Intersect operator helps combine two select statements and returns only those records
that are common to both the select statements. So, after we get Table A and Table B over here and
if we apply the Intersect operator on these two tables, then we will get only those records that are
common to the result of the select statements of these two.
Syntax: SELECT column_list FROM table1 INTERSECT SELECT column_list FROM table2
26.How can you say that Database testing is different from that of GUI testing?
GUI testing is always performed at the front end whereas the Database testing is performed
at the back end
When it comes to dealing with the testable items, generally the users prefer GUI testing.
These items are present clearly./ On the other hand, the Database testing deals with the
testable items that are hidden and are not directly visible to the users
Structured Query Language largely matters in Database approach where the same doesn’t
have any application with the GUI
Invalidating the test boxes are a part of GUI database whereas the Database testing is totally
different in this manner
27.What do you mean by data-driven test?
Data-driven testing is a term used in the testing process whereas test scripts while execution
read test data and/or output values from data files (Data pools, Excel files, ADO objects, CSV files,
ODBC sources) instead of reading the same hard-coded values each time. The test helps testers in
checking the efficiency of the application in handling various inputs.
28.What are the ACID properties?
A view is a virtual table, it is a named set of SQL statements that can be later referenced and used as a table.
create view view_name as select column1, column2 from table_name where condition;
30.List some advantages and disadvantages of Stored Procedure?
Advantages:
A Stored Procedure can be used as a modular programming which means create once,
store and call for several times whenever it is required. This supports faster execution. It also
reduces network traffic and provides better security to the data.
Disadvantage:
The only disadvantage of Stored Procedure is that it can be executed only in the database
and utilizes more memory in the database server.