0% found this document useful (0 votes)
8 views131 pages

Chapter 1 Introductionn

Uploaded by

Fikadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views131 pages

Chapter 1 Introductionn

Uploaded by

Fikadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 131

Chapter 1: Introduction to Databases

and
Database Management Systems

27/10/2024 Fundamental of Database System By Dagne w Slide 1- 1


Contents
• Meaning of the term database
• Application areas of database systems
• Meaning of the term Database Management System
(DBMS).
• Components of the DBMS environment.
• Typical functions of a DBMS.
• Advantages/disadvantages of DBMSs
• Historical overview of Database models
• Stages of Database System Development

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.

27/10/2024 Fundamental of Database System By Slide 1- 3


Dagne w
What is a Database?
• “A set of information held in a computer”
Oxford English Dictionary
• “One or more large structured sets of
persistent data, usually associated with
software to update and query the data”
Free On-Line Dictionary of Computing
• “A collection of data arranged for ease and
speed of search and retrieval”
Dictionary.com

27/10/2024 Fundamental of Database System By 4


Dagne w
Database
• Shared collection of logically related data
(and a description of this data), designed
to meet the information needs of an
organization.

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.

A database is typically available to a community


of users, with possibly varying requirements.

27/10/2024 Fundamental of Database System By 7


Dagne w
“Organised Collection of
Symbols”
For example:
StudentId Name CourseId
S1 Anne C1
S1 Anne C2
S2 Boris C1
S3 Cindy C3

The symbols are organised into rows and columns, thus


forming a table. One of the rows is different in kind from the
others.
27/10/2024 Fundamental of Database System By 8
Dagne w
“To Be Interpreted as a True
Account”
For example (from the table just shown):

StudentId Name CourseId


S1 Anne C1

Perhaps those green symbols, organised as they are with


respect to the blue ones, are to be understood to mean:

“Student S1, named Anne, is enrolled on course C1.”

27/10/2024 Fundamental of Database System By 9


Dagne w
“Collection of Variables”
ENROLMENT
StudentId Name CourseId
S1 Anne C1
S1 Anne C2
S2 Boris C1
S3 Cindy C3
S4 Devinder C1

ENROLMENT is a variable. Perhaps the table we saw


earlier was once its value. If so, it (the variable) has been
updated since then (the row for S4 has been added).
27/10/2024 Fundamental of Database System By 10
Dagne w
What Is a Relational Database?
A database whose symbols are organised into a
collection of relations. Here is a relation, shown in
tabular form:
StudentId Name CourseId
S1 Anne C1
S1 Anne C2
S2 Boris C1
S3 Cindy C3
S4 Devinder C1
Might be the value currently assigned to ENROLMENT, a
relation variable (“relvar”).
27/10/2024 Fundamental of Database System By 11
Dagne w
“Relation” not equal to “Table”
This table is different from the one we have just seen,
but it represents the same relation:
Name StudentId CourseId
Devinder S4 C1
Cindy S3 C3
Anne S1 C1
Boris S2 C1
Anne S1 C2
In other words, the relation represented does not
depend on the order in which we place the rows or the
columns in the table.
27/10/2024 Fundamental of Database System By 12
Dagne w
Anatomy of a Relation
StudentId Name CourseId
S1 Anne C1

attribute name attribute values n-tuple, or tuple.


This is a 3-tuple.
The tuples
constitute the body
of the relation.
Heading (a set of attributes) The number of
The degree of this heading is 3, tuples in the body
which is also the degree of the relation. is the cardinality of
the relation.

27/10/2024 Fundamental of Database System By 13


Dagne w
Data Dictionary - Metadata
• The dictionary holds
or catalog stores information about the
– Descriptions
database itself of database objects (tables, users, rules, views,
• Thisindexes,…)
is data about data or ‘metadata’
– Information about who is using which data (locks)
• Almost every aspect of the DBMS uses the dictionary
– Schemas and mappings

27/10/2024 Fundamental of Database System By 14


Dagne w
Databases
• Trainindexes
Web timetables
• Library bookings
Airline catalogues
• Medical
Credit card
records
details
• Bank accounts
Student records
• Stock control
Customer histories
• Personnel
Stock market
systems
prices
• Product catalogues
Discussion boards
• Telephone
and so on…directories

27/10/2024 Fundamental of Database System By 15


Dagne w
Database Systems
• Database
A databasesystems
systemallow
consists
users
of to
– Store
Data (the database)
– Update
Software
– Retrieve
Hardware
– Organise
Users
– Protect
• We focus mainly on the software
their data.

27/10/2024 Fundamental of Database System By 16


Dagne w
Application areas of Database Systems

• Banks
• HRM
• Stock Management
– Supermarket
• Library Systems
• Universities
• ETC

17
File Based Systems vs Database System

• File based systems • File based system Problems


– Data is stored in files – No standards
– Each file has a specific format – Data duplication
– on
– Programs that use these files depend Data dependence
knowledge about that
format – No way to generate ad hoc
queries
– No provision for security,
recovery, concurrency, etc.

27/10/2024 Fundamental of Database System By 18


Dagne w
Database Users
• Database
End usersAdministrator (DBA)
– Designs
Use the database
& managessystem
the database
to achieve
system
some goal
• Database
Application
systems
developers
programmer
– Write
Writessoftware
the database
to allow
software
end users
itselfto interface with the database
system

27/10/2024 Fundamental of Database System By 19


Dagne w
DBMS
• A software system that
enables users to define,
create, and maintain the
database and that provides
controlled access to this
database.

20
Database application program

• A software program that


interacts with the database by
issuing an appropriate request
(typically an SQL statement) to
the DBMS.

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

27/10/2024 Fundamental of Database System By 22


Dagne w
What Is a DBMS?
A piece of software for managing databases
and providing access to them.
A DBMS responds to imperatives (“statements”)
given by application programs, custom-written
or general-purpose, executing on behalf of users.
Imperatives are written in the database language
of the DBMS (e.g., SQL).
Responses include completion codes, messages and
results of queries.

27/10/2024 Fundamental of Database System By 23


Dagne w
What the DBMS does
• DBMS
Providesprovides
users with
– Persistence
Data definition language (DDL)
– Concurrency
Data manipulation language (DML)
– Integrity
Data control language (DCL)
– Security
• Often these are all the same language
– Data independence
• Data Dictionary
– Describes the database itself

27/10/2024 Fundamental of Database System By 24


Dagne w
What Does a DBMS Do?
In response to requests given by application programs:
• creates and destroys variables
• takes note of integrity rules (constraints)
• takes note of authorisations (who is allowed to do
what, to what)
• updates variables (honouring constraints and
authorisations)
• provides results of queries

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

27/10/2024 Fundamental of Database System By 31


Dagne w
Database Users
• System designers and implementors: Design and implement
DBMS packages in the form of modules and interfaces and test
and debug them. The DBMS must interface with applications,
language compilers, operating system components, etc.
• Tool developers: Design and implement software systems
called tools for modeling and designing databases,
performance monitoring, prototyping, test data generation, user
interface creation, simulation etc. that facilitate building of
applications and allow using database effectively.
• Operators and maintenance personnel: They manage the
actual running and maintenance of the database system
hardware and software environment.
27/10/2024 Fundamental of Database System By Slide 1- 32
Dagne w
When not to use a DBMS
• Main inhibitors (costs) of using a DBMS:
– High initial investment and possible need for additional
hardware
– Overhead for providing generality, security, concurrency
control, recovery, and integrity functions
• When a DBMS may be unnecessary:
– If the database and applications are simple, well defined, and
not expected to change
– If access to data by multiple users is not required
• When a DBMS may be infeasible
– In embedded systems where a general-purpose DBMS may
27/10/2024not fit in available storage
Fundamental of Database System By Slide 1- 33
Dagne w
Types of Databases and Database Applications

• 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

27/10/2024 Fundamental of Database System By Slide 1- 34


Dagne w
Recent Developments
• Social Networks started capturing a lot of information
about people and about communications among
people-posts, tweets, photos, videos in systems such
as:
- Facebook
- Twitter
- Linked-In
• All of the above constitutes data
• Search Engines, Google, Bing, Yahoo: collect their
own repository of web pages for searching purposes
27/10/2024 Fundamental of Database System By Slide 1- 35
Dagne w
Recent Developments
• New technologies are emerging from the so-called
non-SQL, non-database software vendors to
manage vast amounts of data generated on the
web:
– Big data storage systems involving large
clusters of distributed computers NOSQL
(Non-SQL, Not Only SQL) systems (Chapter
24)
• A large amount of data now resides on the “cloud”
which means it is in huge data centers using
thousands
27/10/2024
of machines.
Fundamental of Database System By Slide 1- 36
Dagne w
What is “big data”?
• "Big data are high-volume, high-velocity, and/or high-
variety information assets that require new forms of
processing to enable enhanced decision making, insight
discovery and process optimization” (Gartner 2012)
– Three Vs? Other Vs?
• Veracity: refers to the trustworthiness of the data
• Value: will data lead to the discovery of a critical causal effect?
• Bottom line: Any data that exceeds our current
capability of processing can be regarded as “big”
– Complicated (intelligent) analysis of data may make a small
data “appear” to be “big”
27/10/2024 Fundamental of Database System By 37
Dagne w
Impact of Databases and Database Technology

• Businesses: Banking, Insurance, Retail,


Transportation, Healthcare, Manufacturing
• Service industries: Financial, Real-estate, Legal,
Electronic Commerce, Small businesses
• Education : Resources for content and Delivery
• More recently: Social Networks, Environmental
and Scientific Applications, Medicine and
Genetics
• Personalized applications: based on smart mobile
devices
27/10/2024 Fundamental of Database System By Slide 1- 38
Dagne w
DBMS

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

• Perceived by user as a collection of tables


for data storage
• Tables are a series of row/column
intersections
• Tables related by sharing common entity
characteristic (s)

54
A simplified architecture for a database system

27/10/2024 Fundamental of Database System By Slide 1- 55


Dagne w
Example of a Database
• Mini-world for the example:
– Part of a UNIVERSITY environment
• Some mini-world entities:
– STUDENTs
– COURSEs
– SECTIONs (of COURSEs)
– (Academic) DEPARTMENTs
– INSTRUCTORs

27/10/2024 Fundamental of Database System By Slide 1- 56


Dagne w
Example of a Database
• Some mini-world relationships:
– SECTIONs are of specific COURSEs
– STUDENTs take SECTIONs
– COURSEs have prerequisite COURSEs
– INSTRUCTORs teach SECTIONs
– COURSEs are offered by DEPARTMENTs
– STUDENTs major in DEPARTMENTs
• Note: The above entities and relationships are typically
expressed in a conceptual data model, such as the entity-
relationship (ER)

27/10/2024 Fundamental of Database System By Slide 1- 57


Dagne w
Example of a Simple Database

27/10/2024 Fundamental of Database System


Slide 1-By
58
Dagne w
The relational model

Fundamental of Database System By


Dagne w
Example of a Simplified Database Catalog

27/10/2024 Fundamental of Database System By Slide 1- 60


Dagne w
Relational Database: Definitions
• Relational database: a set of relations.
• Relation: made up of 2 parts:
– Instance : a table, with rows and columns.
• #rows = cardinality
– Schema : specifies name of relation, plus name and type of each
column.
• E.g. Students(sid: string, name: string, login: string,
age: integer, gpa: real)
• #fields = degree / arity
• Can think of a relation as a set of rows or tuples.
– i.e., all rows are distinct

Fundamental of Database System By Dagne w


61
27/10/2024
Example Instance of Students Relation

sid name login age gpa


53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8

 Cardinality = 3, degree = 5 , all rows


 Dodistinct
all columns in a relation instance have to
be distinct?
Fundamental of Database System By Dagne w 62
Example Instance of Enrolled Relation
sid cid grade
53666 Carnatic101 C
53666 Reggae203 B
53650 Topology112 A
53666 History105 B

Fundamental of Database System By Dagne W 63


The SQL Query Language
• Developed by IBM (system R) in the 1970s
• Need for a standard since it is used by many
vendors
• Standards:
– SQL-86
– SQL-89 (minor revision)
– SQL-92 (major revision, current standard)
– SQL-99 (major extensions)
27/10/2024 Fundamental of Database System By 64
Dagne w
SQL - A language for Relational DBs
• SQL: standard language
• Data Definition Language (DDL)
– create, modify, delete relations
– specify constraints
– administer users, security, etc.
• Data Manipulation Language (DML)
– Specify queries to find tuples that satisfy criteria
– add, modify, remove tuples

Fundamental of Database System By Dagne w 65


27/10/2024
2.Types of SQL Commands?

1. DDL ( Data Definition Language)


Create, alter, drop, truncate, rename
2. DML ( Data Manipulation Language)

insert, update, delete


3. DRL/DQL ( Data Retrieval Language/Data Query Language)
select
4. TCL ( Transaction Control Language)
Commit, Rollback, save point.
5. DCL (Data Control Language)
Grant, Revoke
SQL Overview
• CREATE TABLE <name> ( <field> <domain>, … )

• INSERT INTO <name> (<field names>)


VALUES (<field values>)

• DELETE FROM <name>


WHERE <condition>

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

– whenever tuples are added or


modified.
CREATE TABLE Enrolled
• Another example: the Enrolled (sid CHAR(20),
cid CHAR(20),
table holds information about grade CHAR(2))
courses students take.
27/10/2024 Fundamental of Database System By 68
Dagne w
Adding and Deleting Tuples
• Can insert a single tuple using:
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (‘53688’, ‘Smith’, ‘smith@ee’, 18, 3.2)

• Can delete all tuples satisfying some


condition (e.g., name = Smith):

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)

27/10/2024 Fundamental of Database System By 70


Dagne w
Adding and Deleting Tuples
• Students relation after inserts:
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
53600 Greengreen@ee 18 3.5

27/10/2024 Fundamental of Database System By 71


Dagne w
Adding and Deleting Tuples
 Can delete all tuples satisfying some
condition (e.g., name = Smith):
DELETE
FROM Students S
WHERE S.name = 'Smith'

 Students instance after delete:

sid name login age gpa


53666 Jones jones@cs 18 3.4
53600 Green green@ee 18 3.5
72
27/10/2024
The SQL Query Language
• To find all 18 year old students, we can
write: sid name login age gpa
SELECT * 53666 Jones jones@cs 18 3.4
FROM Students S
53688 Smith smith@ee 18 3.2
WHERE S.age=18

• To find just names and logins, replace the first line:


SELECT S.name, S.login from Students S

27/10/2024 Fundamental of Database System By 73


Dagne w
Adding and Deleting Tuples
• Insert tuples into the Enrolled instance:
INSERT INTO Enrolled (sid, cid, grade)
VALUES ('53831', 'Carnatic 101', 'C')
INSERT INTO Enrolled (sid, cid, grade)
VALUES ('53831', 'Reggae 203', 'B')
INSERT INTO Enrolled (sid, cid, grade)
VALUES ('53650', 'Topology 112', 'A')
INSERT INTO Enrolled (sid, cid, grade)
VALUES ('53666', 'History 105', 'B')

27/10/2024 Fundamental of Database System By 74


Dagne w
Querying Multiple Relations
• What does the following query compute?
SELECT S.name, E.cid
FROM Students S, Enrolled E
WHERE S.sid=E.sid AND E.grade='B'

Given the following sid cid grade


instance of Enrolled (is this 53831 Carnatic101 C
53831 Reggae203 B
possible if the DBMS
53650 Topology112 A
ensures referential 53666 History105 B
integrity?):
we get: S.name E.cid
Jones History 105
27/10/2024 Fundamental of Database System By 75
Dagne w
Primary and Candidate Keys in SQL
• Possibly many candidate keys (specified using
UNIQUE), one of which is chosen as the primary
key. CREATE TABLE Enrolled
 “For a given student and (sid CHAR(20),
course, there is a single cid CHAR(20),
grade.” vs. “Students can grade CHAR(2),
PRIMARY KEY (sid,cid) )
take only one course, and
receive a single grade for that CREATE TABLE Enrolled
course; further, no two (sid CHAR(20),
students in a course receive cid CHAR(20),
the same grade.” grade CHAR(2),
PRIMARY KEY (sid),
 Used carelessly, an IC can
27/10/2024 UNIQUE (cid, grade)
Fundamental of Database System By 76 )
prevent the storage of Dagne w
Primary and Candidate Keys in SQL

• For Students relation with SID as the primary key


CREATE TABLE Students
(sid CHAR(20), name CHAR(20),
login CHAR(10), age INTEGER,
gpa REAL, PRIMARY KEY (sid) )
 Are there any separate fields or combinations
of fields which also are candidates for
primary key?
– How about login?
– How about age?
– How about age
27/10/2024
& gpa?
Fundamental of Database System By
Dagne w
77
Foreign Keys in SQL
• Only students listed in the Students relation
should be allowed to enroll for courses.
CREATE TABLE Enrolled
(sid CHAR(20), cid CHAR(20), grade CHAR(2),
PRIMARY KEY (sid,cid),
FOREIGN KEY (sid) REFERENCES Students )
Enrolled
sid cid grade Students
sid name login age gpa
53666 Carnatic101 C
53666 Reggae203 B 53666 Jones jones@cs 18 3.4
53650 Topology112 A 53688 Smith smith@eecs 18 3.2
53666 History105 B 53650 Smith smith@math 19 3.8

27/10/2024 Fundamental of Database System By 78


Dagne w
Foreign Keys in SQL
• Creates the customer information relation
CREATE TABLE Customer_Info
(name CHAR(20), addr CHAR(40),
phone CHAR(10), email char (40),
PRIMARY KEY (name, addr))
 Now create the bank account relation with a
foreign key
CREATE TABLE Bank_Acct
(acct CHAR (4), name CHAR (20),
address char (40), balance REAL,
PRIMARY KEY (acct) ,
Foreign Key (name, address) references Customer_Info)
27/10/2024 Fundamental of Database System By 79
Dagne w
Foreign Key
• Can a foreign key refer to the same
relation?
• Example
– Each student may have a partner who must be
also a student.
– How about a student who does not have
partner?
– NULL introduced here.
27/10/2024 Fundamental of Database System By 80
Dagne w
Views
• Allows each user to have his
or her own view of the
database.

• A view is essentially some


subset of the database.

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

 Views can be dropped using the DROP VIEW


command.
 How to handle DROP TABLE if there’s a view on the
table?
- DROP TABLE command
27/10/2024
has options
Fundamental of Database System By
to let the user
83
Dagne w
View
• CREATE VIEW Goodstudents(sid, gpa) as select S.sid,
S.gpa from Students S where S.gpa> 3.0
• How about the following:
– INSERT into S VALUES(“100”,”JONE”,3.2)
– INSERT into S VALUES(“101”, ”Mike”,2.8 )
– DELETE from S where S.id = “100”
– INSERT into GS VALUES(“111”, 3.2)
– INSERT into GS VALUES(“112”, 2.8)
– DELETE from GS where S.id = “111”

27/10/2024 Fundamental of Database System By 84


Dagne w
Querying Multiple Relations
• What does the following query compute?
SELECT S.name, E.cid
FROM Students S, Enrolled E
WHERE S.sid=E.sid AND E.grade='A'

Given the following sid cid grade


instance of Enrolled 53831 Carnatic101 C
53831 Reggae203 B
53650 Topology112 A
53666 History105 B

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

• Describes scope and


boundaries of database
system, including its major
user views.

• Describes how database


system will interface with
other parts of the 88

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

• Process of creating a design


that will support the
organization’s mission
statement and objectives for
the required database system.
• Two main phases of database
design:
– Logical database design
– Physical database design.
92
DBMS selection
• Selection of an appropriate
DBMS to support the database
system.

• Undertaken at any time prior


to logical design provided
sufficient information is
available regarding system
requirements.
93
Application design

• Design of user interface and


application programs that use
and process the database.
• Database and application
design are parallel activities.

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

• Physical realization of the


database and application designs.
– Use DDL to create database schemas and empty
database files.
– Use DDL to create user views.
– Use 3GL or 4GL to create the application programs,
which includes database transactions.
– Use DDL to implement security and integrity
controls. However, some may be defined using
DBMS utilities or operating system.

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?

1. DDL ( Data Definition Language)


Create, alter, drop, truncate, rename
2. DML ( Data Manipulation Language)

insert, update, delete


3. DRL/DQL ( Data Retrieval Language/Data Query Language)
select
4. TCL ( Transaction Control Language)
Commit, Rollback, save point.
5. DCL (Data Control Language)
Grant, Revoke
3.SQL query can start with below commands/words?

Select : Get data from database tables.


Update : Update data in a database table.
Delete : Delete data from database table.
Insert Into : Insert new data in a database table
Crete Database : Creates a database.
Alter Database : Modifies a database.
Create Table : Create new table.
Alter Table : Modifies a table.
Drop Table : Delete’s a table.
Create Index : Creates an index (search key).
Drop Index : Deletes an index.
4.How to use column in various data types?
Varchar: - To store alpha numeric & special characters size from 0 to 65535 varchar [not default
size].
Float: - To store number with decimal point size is float (x,4) X no: of digits before decimal
point, Y no :of digits after decimal point.
Bigint: - To store large number without decimal point.
Double: - To store large no: of with decimal point.
Int: - To store numbers without decimal point [20.5] no: of digits in number up to 255.
Char: - To store alpha numeric & specific char size from 0+0.255, default size 15%.
Date: - To store dates in yyyy-mm-dd size from 2002-01-10 to 2018-04-23.
Data time: - To store data along with time format: yyyy-mm-dd to hh:mm:ss.
Size: 2000-01-07 00:00:00 to 2001-02-04 23:37:59
5.Which constraints we can use while creating a database in SQL?
Constraint can be used to specify the limit on the data type of table. Constraint can
be specified while creating or altering the table statement. Sample of constraint are.
Primary Key: - A combination of a not null & unique it is useful to uniquely identifies each row
in a table.
Foreign key: - Uniquely identifies a row in another table.
Default: - Sets a default value for a column when no value is specified.
INDEX: - Used to create & retrieve data from the database very quickly.
Not Null: - Ensure that a column can’t have a null value.
Unique: - Ensure that all values in a column are different.
Check: - Ensure that all value in a column statistics a specific condition.
6.Differences between Drop, Truncate & delete?

• 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 ?

 Displays all the records from multiple tables without duplicates.


Select num from a union select num from b;
 Displays all the records from multiple tables including duplicates.
Select num from a union all select num from b;
 Displays common records from multiple tables
Select num from a intersect select num from b;
 Displays records which are not present in B
Select num from a minus select num from b;
 Displays records from B which are note present in A
Select num from b minus select num from a;
9.What are different JOINS used in SQL?

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?

i. Sub-queries as scalar operand.


ii. Comparisons using sub-queries.
iii. Sub-queries with All, Any, In/Some.
iv. Row Sub-queries.
v. Sub-queries with exists/not exists.
vi. Co-related Sub-queries.
vii. Sub-queries in the from clause.
12.What are transactions and their controls?
A transaction can be defined as the sequence task that is performed on databases in a
logical manner to gain certain results. Operations performed like Creating, updating, deleting
records in the database come from transactions.
In simple words, we can say that a transaction means a group of SQL queries executed
on database records.
There are 4 transaction controls language such as
COMMIT: It is used to save all changes made through the transaction
ROLLBACK: It is used to roll back the transaction such as all changes made by the transaction
are reverted back and database remains as before
SET TRANSACTION: Set the name of transaction
SAVEPOINT: It is used to set the point from where the transaction is to be rolled bac k
13.What is Transactions in SQL?

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?

Lock table tablename read;


 The session that holds the read lock can only read data from the table but cannot and
other sessions cannot write data to the table until the read lock is released.
 If the session is terminated, either normally or abnormally. My-SQL will release all the
locks implicitly.
Select * from students; //available this query
Insert/update/delete…..Not available
20.What is Write 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.

Select * from students;


Insert/update/delete queries hold until write lock is released.
21.What is the main difference between ‘BETWEEN’ and ‘IN’ condition operators?

BETWEEN operator is used to display rows based on a range of values in a row


whereas the IN condition operator is used to check for values contained in a specific set of
values.
Examples
SELECT * FROM Students where ROLL_NO BETWEEN 10 AND 50;
SELECT * FROM students where ROLL_NO IN (8,15,25);
22.What is Auto Increment in SQL?

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.

AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword


can be used in SQL SERVER.
23.Explain the types of Indexes?

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?

ACID properties refer to the four properties of transactions in SQL


Atomicity –All the operations in the transaction are performed as a whole or not performed at all.
Consistency – State of database changes only on successfully committed transactions.
Isolation – Even with concurrent execution of the multiple transactions, the final state of the DB
would be the same as if transactions got executed sequentially. In other words, each transaction is
isolated from one another.
Durability – Even in the state of crash or power loss the state of the committed transaction
remains persistent.
29.What is a View in SQL?

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.

You might also like