Unit 1 1
Unit 1 1
Unit 1 1
DATA:
It is any fact that can be recorded (or) it is a raw material
that can be processed on any computer machine.
EXAMPLE:Text(names),Numbers(Phone_numbers),Image
s,Pictures,Videos, Speech etc......
EXAMPLE:
➔ University database contains entities such as
student,courses, faculty and class rooms.
➔ Relationship between entities such as student
enrollment in courses,faculty teaching courses and use
class rooms for courses.
➔ They are different kinds of data base:
1.Traditional Data Base
2.Multimedia Data Base
3.GIS Data Base
4.Relational Data Base
5.Data ware Housing
BY CSE-3
2.Multimedia Data Base:
It contains videos like speech ,songs,movies etc.....
EX: YOU TUBE
BY CSE-3
*Where DBMS being used? (or) Applications of DBMS:
BY CSE-3
➢ File System: It is a method of Storing and Organising
the computer files and whatever data they contain easy
to find and access them.
(3)Data Dependency:
One file is depended on another file and these
are contains paticular physical format that are developed by
programmers.
(4)Data Redundancy:
It means the same amount of data stored in a
different places that is data redundancy.
BY CSE-3
(5)Data Security:
The security of data is low in the file system that
can be easy to accesible.
(6)Transaction Problem:
File systems are not support the transaction and ACID
properties.
A - Atomicity
C - Consistency
I - Isolation
D – Durability
(7)Concurrent Problems:
(1)Data Independency:
The DBMS provides an abstract view of data and hide
such details.
BY CSE-3
(2)Reduce DataRedundancy:
➔ In file system the data can be stored in a
different places and there is a chances of
duplication of data and also there is a waste of
space.
➔ But in DBS ,the files are stored in single
database.The hold data is stored only once so there
is no chance of duplication of data.
(3)Sharing of Data:
➔ In DBS,the data can be shared between authorised
users of DB.
➔ All the users have own rights to access the data.
➔ The DBA(Database Administrator)has complete
access of DB and he can assign user to access the data.
(4)Data Consistency:
(5)Data Integrity:
It means that data in database is always
accurate or correct that can be decrease the duplication of
data also data inconsistency.
(6)Security:
➔ It means protecting your data from unauthorised users.
➔ Data in a DB we kept secure and safe.
BY CSE-3
➔ Only authorised users should be grant to access the
DB.
(2)Complexity:
Developers,Designers,DBA and endusers of DB must
have complete skills if they want to use it properly
otherwise there is a chances of loss of data (or) database
failure.
(4)DataBase Failure:
All the files are stored in a single DB.So, there is a
chances of failure become more.Any accidental failure of
component may cause loss of valuable data.
BY CSE-3
(5)Size:
A DBMS become big software,Lots of space and the
memory to run its applications and gains bigger size.
(6)Currency Maintainence:
DBMS should be update according to the current
scenario and new threats comes daily,so DBMS update
itself daily.
(7)Performance:
The total data can be stored in a same DB and there is a
chances of low in the perforamance of Computer System.
(1)Data:
Data stored in database include numerical and non-
numerical data,audio,video etc.
(2)Hardware:
It includes Various storage devices,input and output
devices.
(3)Software:
It includes operating systems,Network Software and
application programs.
BY CSE-3
(4)Users:
There are different types os database users in DBS like
DBA(Database Administrator),Database designer,Endusers
and Application users.
DATABASE USERS:
There are two types of database users.
1.Actors on the scene
2.Workers behind the scene
Database Administrator(DBA):
A person who performs all activities related to
maintaining a database responsibilies includes
designing,implementating and maintaining a database.
BY CSE-3
3.Using storage properly:
It means proper use of storage with space requirement
and adding new storage space (disk drives)when required.
6.Working Developers:
The DBA responsible for a person well-known in sql
server.
7.Transferring of data:
The DBA responsible for importing and exporting the
data from the sql server.
2.DATABASE DESIGNERS:
They are responsibel for identifying the how much of
data can stored and way to organising.
BY CSE-3
3.END USERS:
➢ They are responsible for access the database for
quering,updating and report generation.
(b)Naive/Parametric Endusers:
They are biggest group of users and frequently update
the database using “canned trasactions”.
Ex:
1.Bank tellers check account balance,withdraw,deposites.
2.Reservations gor airlines and hotels etc checks the
availability of seats or rooms and make reservations.
(c)Sophisticated Endusers:
Engineers,Scientists,Business Analyst are came under
“Sophisticated Endusers”.
(d)Standalone Endusers:
They are maintain personal database with particular
software package.
Ex: Financial
BY CSE-3
(4)System Analyst,Application Programmers and
Software Engineers:
(a)Tool Developers:
Design and develop the software tools related to DBS
design,performance ,monitoring etc.
(b)Operators:
They are responsible for day to day operations of
Computer System.
DATABASE MODELS:
BY CSE-3
(1)Hierarchiral Model:
➔ In this model data in the form of tree like structure with
a single root to which all other data is linked.
➔ In this model childs have single parent node.
➔ In this model data organised in One-to-Many
Relationship.
EX:
Department
(2)Network Model:
➔ It is extension of Hierarchical Model.
➔ It is a graph like structure.
➔ The parent may have multiple childs also the child
may have multiple parents.
➔ In this model data organised in Many-to-Many
Relationship.
Ex:
A
B1 B2
BY CSE-3
C1 C2 C3
(3)Entity-Relationship Model(ER Model):
address Class
(4)Relational Model:
BY CSE-3
➔ The basic structure of data in Relational Models in
Tables.
➔ Tables also known as “Relation”.
Ex:
DATABASE LANGUAGE:
BY CSE-3
(2)DML- DataManipulation Language.
(3)TCL- Trasaction Control Language.
(4)DCL- Data Control Language.
(2)Alter:
Alter command is used for alternation of data in a database.
• To add column to the exist table.
• To add multiple columns to existing table.
• Drop a column.
• Modify a column.
• Rename a column.
Drop a column:
Syntax: alter table table_name drop(column_name
datatype);
BY CSE-3
Ex: alter table student drop(age int);
Modify a column:
Syntax: alter table table_name modify(column_name
datatype);
Ex: alter table student modify(marks int);
Rename a column:
Syntax: alter table table_name rename(old_column name
to new_column name);
Ex: alter table student rename id to sid;
(3)Truncate Command:
➔ This command is used for remove all the records
from the table but it can’t destroy the table structure.
➔ When we apply truncate command on a table it’s
primary key is initialised.
Syntax: Truncate table table_name;
(4)Drop command:
➔ This command is used for remove table from the
database.
➔ It destroy the table structure.
Syntax: drop table table_name;
Ex: drop table student;
BY CSE-3
(5)Rename command:
This command is used for rename a tablename.
Syntax: rename old_tablename to new_tablename.
(1)INSERT command:
This command is used for to insert data into a table.
(2)SELECT command:
This command is used to retrive data from database.
Syntax: select *from table_name;
Ex: select *from student;
BY CSE-3
503 lmn 22
(3)DELETE command:
This command is used to delete data from table.It also
delete particular row.
Syntax: delete from table_name where condition;
(4)UPDATE command:
This command is used to update a row of a table.
Syntax: update table_name set column_name=value where
condition;
Ex: update student set age=27 where sid=501;
select *from student;
BY CSE-3
➔ These are used to control the transaction in a
database.
sid name
501 abc
502 xyz
BY CSE-3
insert into student values(506, “rajesh”);
savepoint C;
select *from student;
sid name
501 abc
502 ram
503 lmn
504 raj
505 rock
506 rajesh
rollback to A;
select *from student;
sid name
501 abc
502 ram
503 lmn
504 raju
(i)GRANT:
It is used to provide access (or) privilages (or)
permission on the databases objects to the user.
BY CSE-3
Syntax: grant privilage_name on object_name to
{user_name/public/role_name}[with grant option];
where,
(ii)REVOKE:
It is used to removes access rights (or) privilages to the
databases objects.
Syntax: revoke privilage_name on object_name from
{username / public / role_name }
BY CSE-3
Name Age
Imn 22
pqr 23
xyz 24
Output:
Name Age
Imn 22
pqr 23
xyz 24
jesus 37
Name Age
BY CSE-3
Imn 22
pqr 23
xyz 24
Truncate:
Syntax: truncate view view_name;
select *from view_name;
Ex:
truncate view student_view;
select *from view_name;
Output:
Drop:
Data independence:
BY CSE-3
1.Physical data inpedence:
It is the capacity of change the schema at
internal level without changes min the schema at
conceptual level.
2.Logical data inpedence:
The capacity of change the schema at
conceptual level without changes in the schema at external
level.
External schema
(highest level)
Internal schema
(Low level)
BY CSE-3
database
(1)INTERNAL LEVEL:
2.CONCEPTUAL LEVEL:
BY CSE-3
➔ For example university database contains entities
such as students,course,faculty,classrooms.
3.EXTERNAL LEVEL:
E-R definition:
➔ The pictorial or graphical form of data is known as
“Entity-Relationship(E-R) model”.
➔ It is conceptual view of database.
1.Entity:
➔ It is an object in a real world that can be different
from other objects.
➔ It is represented as Rectangle ( )
BY CSE-3
Ex: University database contains entities like
students,faculty,courses,class rooms etc.
name sid
student
marks age
Entity type:
➔ It is a collection of entities that have same
attributes.
➔ It is intension of entity set.
Ex:E1 is an entity having entity type student and set of all
students is called “entity set”.
Weak Entity:
➔ The entity doesnot have primary key.
➔ It is represented as double rectangle.
Strong entity:
➔ The entity have a primary key is called as “Strong
entity”.
BY CSE-3
Associative entity:
➔ The entity which look like a relationship.
➔ It is represented as diamond in a rectangle.
2. Attributes:
➔ The property or characteristics of an entity is
called as “Attributes”.
➔ It is represented as eclipse or oval in E-R model.
➔ Ex:student is an entity which contains
name,sid,marks,age.
age sid
student
name marks
Types of Attributes:
a.Simple vs Composite Attributes
b.Single valued vs Multivalued Attributes
c.Stored vs Derived Attributes
d.Complex Attributes
a.Simple Attributes:
➔ Attribute which contains single atomic value
which can’t be divide further.
Ex: Student id,Student ph.no,ph num etc.
BY CSE-3
age sid
student
Ph num
Composite Attributes:
Middle_name
Door.No.
First_name Pincode
Name Address
Street Name
Last_name
Student
BY CSE-3
b)Single valued vs Multivalued Attributes:
Qualifications Emails
Student
Phone_Nimbers
BY CSE-3
➔ It is represented as dotted eclipse
Ex:Student age
Student
D.Complex Attribute:
➔ It is the collection of both composite and multivalued
Attributes.
Address
Temporary
Address Permanant
Address
3.Relationship:
➔ Relation between entity or association among
entities is called as “Relationship”.
BY CSE-3
➔ It is represented as diamond in ER model.
Types of Relationship:
BY CSE-3
b)Ternary Relationship
c)n-ary Relationship
a)Binary Relationship:
➔ It means relation between two entities its degree is
two.
Student Faculty
b)Ternary Relationship:
➔ It means relation between three entities and its
degree is three.
Department
Student Faculty
c)n-ary Relationship:
It means relation between n entities and its degree is n
BY CSE-3
Binary Relationship is furher divided into
1.One to One mapping(1-1)
2.One to Many mapping(1-N)
3.Many to One mapping(N-1)
4.Many to Many mapping(N-N)
Cardinality:
The no.of times an entity of entity set participated in a
relationship is known as “Cardinality”
1.One to One mapping(1-1):
A B
O O
M1 F1
O O
M2 F2
O O
M3 F3
BY CSE-3
➔ One entity from entity set A that can be relation
with more than one entity from entity set B can be
relation with atmost one entity from entity set A.
➔ For example one course taken by many students
however many students taken one course.
A B
O
S1
O O C1
S2
O O C2
S3
O
A B
O
S1
O O
S2 C1
O O
S3 C2
O
S4
BY CSE-3
4.Many to Many Mapping(N-N):
➔ One entity from entity set A that can be relation
with more than one entity from entity set B and one
entity from entity set B that can be relation with more
than one entity in entity set A.
➔ Ex:One couse taken by many students and one
student taken many courses.
A B
O O
S1
C1
O O S2
C2
O O S3
C3
O O S4
Constraints in ER model:
Integrity Constraints:
➔ These are contains set of rules and used to
maintain quality of information.
➔ These are ensure that you can insert,update and
other process have to performed in such a way that data
integrity is not effected.
BY CSE-3
➔ It is used to guard against accidental failure of
database.
BY CSE-3
In above example cardinality of employee e1 is 1,the
cardinality of d1 is 2
b)Participation:
➔ The minimum no.of times an entity participated in
a relationship.
➔ Some times it is also caleed as minimum
cardinality.
➔ It is further divided into two types
a)Total participation
b)Partial participation
2.Key Constraints:
BY CSE-3
➔ Key attributes or set of attributes that are uniquely
identifies an entity within entity set.
They are two types
1.Primary key
2.Foreign key
a.Primary key:
➔ primary key contains unique values and never
contains new values.
➔ It is unique column in a table.
➔ A table can have only one primary key which
consists of one or more columns.
Ex:
create table student(sid int,name varchar(20),age
int,marks int,primary key(sid));
student table
sid name age marks
501 Raj 40 99
502 Raju 39 98
503 Ram 41 97
504 Ramu 18 92
b.Foreign key:
➔ It means it likes two different tables together and
column in one table that can be pointing to the primary
key in another table.
➔ They act as cross reference between tables.
Course table
cid sid cname
BY CSE-3
1 501 x
2 502 y
3 503 z
eage Dname
BY CSE-3
3.Domain Constraints:
➔ It means that valid set of values of an attribute.
➔ You need to define
➢ data type.
➢ length or size
➢ null value is allowed
➢ default value.
➢ It is the value used is unique.
➢ Range value
➔ Domain Constraints=data type+constraints(not
null/unique/primary key/foreign key/default).
➔ Each table has set of columns and each column has
allows same type of data based on its data
type[int,char].
➔ The column doesnot accept values of any other data
type.
➔ Every attribute is bound to specific range of values for
example,age can not less than zero and a telephone
num cannot contain a digit outside 0 to 9.
➔ The data type related with domains include
character,integer,date,time,currency etc.
Ex:
sid name age
1 a 20
2 b 21
3 c a
BY CSE-3
4.Entity Integrity Constraints:
Rules:
➢ (i) You can not delete record from primary table if
matching record found in secondary table.
➢ (ii) You can not change a primary key in primary table
if that related to the foreign key of the secondary table.
➢ (iii) Secondary table must be NULL on available in
primary table.
BY CSE-3
student table
(primary table)
sid name age
501 a 20
502 b 21
503 c 20
504 d 22
Course table
(Secondary table)
sid cid cname
501 1 abc
502 2 xyz
503 3 ----
504 4 Pqr
Reduction/Conversion of ER diagrams to
tables/Relation:
➔ ER diagram is converted into tables in relational model
because relational models can be easily implemented
by RDBMS like mysql,oracle etc.
➔ Following are used for converting ER diagrams into
tables.
Ex:
Sid Name
Marks
Student
Schema: Student(sid,name,marks)
BY CSE-3
Ex:
last_name
First_name Door.No Pincode
Name
Address
Student
Street Name
sid
Schema:
student(sid,firstname,lastname,dno,streetname,pincode)
BY CSE-3
➔ b)other table will contain the primary key and all
multivalued attributes.
Ex:
sid marks
Student Mobile_num
First table:
Sid marks
Second Table:
sid marks Mobile num
BY CSE-3
RULE 4: Translating relationship into tables.
➢ A relationship set will require one table in relational
model
➢ Attribute of the table are
a)primary key attributes of the participating entity sets.
b)its own descriptive attributes if any.
dept_id b2
eid ename
➔
Works department
Employee in
since
Schema: worksin(eid,deptid,since)
BY CSE-3
➢ one table for entity set “department”.
➢ one table for relationship set “works in”.
m n
A R B
i)A(a1,a2)
a1 a2
ii)R(a1,b1)
a1 b1
BY CSE-3
iii)B(b1,b2)
b1 b2
b1 b2
a1 a2
1 m
A R B
Note: here combine table will be drawn for entity set B and
relationset R.
Ex: R(a1,b1) B(b1,b2) BR(a1,b1,b2).
BY CSE-3
CASE 03:Binary relationship with cardinality ratio m:1
a1 a2 b1
b2
m 1
A R B
a1 a2 b1
b2
A R B
1 1
BY CSE-3
here two tables will be required either combine R with
A or B.
a1 a2 b1
b1 b2
a1 a2
BY CSE-3
a1 b1 b2
Points to remember:
➔ While determining the minimum no.of tables required
for binary relationship with given cardinality
ratio,following rules to remember.
➔ a)for binary relationship with cardinality ratio
m:m,separate and individual table will be drawn for
each set and relationship.
➔ b) for binary relationship with cardinality ratio either
1:m or m:1 always remember many side will consume
the relationship i.e, combined table will be set for
many side entity set and relation set.
➔ c) for binary relationship with cardinality ratio 1:1,two
tables will be required .you can combine the
relationship set with any one of the entity sets.
BY CSE-3
a2 b1
a1 b2
A R B
b1 b2
a1 a2
R B
A
BY CSE-3
here only one table required.
ARB(a1,a2,b1,b2)
a1 b1 b2
a2
A R B
BY CSE-3