DBMS :: (Data Base Management System)
A DBMS refers to a s/w that is responsible for storing,
maintaining and utilizing databases. DBMS is basically a
record keeping system. Ex of DBMS are MS Access, MY SQL
, SQL Lite, MYSQL server , Oracle , FoxPro , Dbase etc.
Data Base:: Data base is defined as the organized
collection of data. Ex: Attendance register , Telephone
directory
Need of DBMS:: Basic needs of DBMS are
1.Data bases reduces data redundancy:: Data
redundancy means duplication of data. Ex: In a college,
student’s records are maintained and the hostel also
maintains record of all those students who live in hostel.
Both college and hostel maintains a separate copy of
student record. But duplication of data may lead to
inconsistency.
Suppose the permanent address of a hostler gets changed.
The hostler student informs about it to the hostel
authorities and the changed address is reflected in the
student’s record. The data for the same student has not
been changed in the college records. If the students forgets
to inform the college authorities or college people
themselves forget to update the student’s record, the same
student’s record differ in two different files
Now which record of the two would be considered accurate.
Suppose college has to send certain information by post.
Then what will happen. The wrong data will get processed.
Data bases control data inconsistency::Inconsistency
means in correct information(Changes made at one place is
not reflected at other place).By controlling redundancy ,
inconsistency can be controlled.
Data base facilitate sharing of data:: Sharing of data
means data in the database may be shared among several
different users. Each user may have access to the data and
each of them may use it for different purposes .For sharing
of data grant command is used.
Data bases enforces standards:: Data base standards are
related to the naming of data , structure of data , format of
data etc.
Standards used in DBMS are
(a). Give meaningful field name
(b).Use consistent data type ie. Don’t use phone _no as
numeric in one table and char in other table. Same field
name in two tables should have same data type.
(c). Don’t use space in table name or field name.
Data base can ensure data security:: Data security
means protection of data against unauthorized person.
To secure database username and passwords must be
applied.
create user <username> identified by <password>
Integrity can be maintained through database:: Data
integrity means accuracy and consistency of data. Data integrity
can be maintained by various error checking and validation
methods.
Data validation :: Let the date format is save as dd/mm/yyyy
format in SQL then date must be in dd/mm/yyyy format and not
in sep 2nd 2007.This is called data validation. There are two basic
rules to ensure data integrity.
a). Entity Integrity :: This rule ensures that every table must have
its own primary key.
b). Referential Integrity :: Referential integrity is based on
primary and foreign key. This rule defines that a foreign key
have a matching primary key.
Table:: Employee
This rule states that the Dept_id(Foreign key) in the
Employee table has a matching valid Dept-id(Primary key)
in the department table.
Emp_id Emp_name Dept_id
Table:: Department
Dept_id Dept_name Dept_zone
Foreign key
Primary key
DataBase Abstraction:: Database Abstraction means
to provide the users only that much information that is
required by them or we can say that the system does
not disclose all the details of data rather it hides
certain details of how data is stored and maintained.
Example :: In a bank database if a customer wants to
know his balance then he is concern to only that part
not even all his details that how his database is stored ,
where is stored and all that.
Levels of Database Abstraction:: There are 3 levels
of database implementation.
1. Internal level
2. Conceptual level
3. External level
Internal level :: Internal level is also called physical level or
storage level. It describes how data are actually stored in the
storage medium.
Conceptual level :: Conceptual level is also called logical
level. It describes what data are actually stored in the
database. This level is related to the structure of the
database.
External level :: External level is also called view level. It
describes the way in which the data are viewed by the users.
Most of the users of the database are not concerned with all
the information contained in the database. Instead, they
need only a part of the database relevant to them.
Sales officer (T1)
Item name
price
Purchase officer (T2)
Item name
Quatity
Item_no integer
Item_name char(10)
Price integer
Quantity integer
Item_no type=byte(38),offset=5
Item_name type=byte(38),offset=7
Price type=byte(38),offset=36
Quantity type=byte(34),offset=15
pPhysical Level
Concept of Data Independance:: The ability to modify a
scheme definition in one level without affecting the scheme
definition in the next higher level is called Data
Independence. There are two levels of data independence.
1) Physical data independence
2) Logical data independence
Physical data independence:: Modify the scheme followed
at the physical level without affecting the scheme followed at
the conceptual level.
Any of the below change in physical level will not affect the
conceptual level.
Using a new storage device like Hard Drive or Magnetic
Tapes.
Change of Location of Database from say C drive to D Drive
Logical data independence:: Modify the scheme followed
at the conceptual level without affecting the scheme
followed at the external level.
Any of the below change in conceptual level will not affect
the external level.
Add/Modify/Delete a new attribute
Merging two records into one
Breaking an existing record into two or more records
Data Models :: Data models are basically concepts that can
be used to describe the structure of a database .The three
data models are used in database management system.
Relational data model
Network data model
Hierarchical data model
1.Relational data model:: In relational data model data is
organized in the form of tables. These tables are called
relations. Relationship b/w record is represented by relation
containing keys.
Let there are three tables(relations)
Suppliers , Items , Shipments
Unit 3.2 Relational Data Model
Rows in a relation are generally referred to as tuples and
columns in a relation are generally referred to as attributes.
2.Network data model:: In Network data model data is
organized in the form of graph structure. Relationship b/w
record is represented by links.
3.Hierarchical data model:: In Hierarchical data model
data is organized in the form of trees. Relationship b/w
record is represented by trees(parent child form).
Root
S1
I2
I3
I6
10
20
20
Tree Structure
Relational Data Models :: Relational data model was
developed by E.F Codd. In this model data is organised in
two dimensional table called relation.
Basic terms used in Relational database ::
Entity :: Name of the table
Relation :: Relation is a table , consists of tuples (rows) and
attributes(columns).A relation must have following
properties.
An item in a given column are of same kind.
All rows of relation must be distinct
Column name of a relation are assigned distinct names.
 Each row must be uniquely identified
Domain :: A domain is a pool of values from which actual
values appearing in a given column are drawn.
Suppno is drawn from above domain in “suppliers” table.
Tuple:: The row of a table is known as tuple.
Attribute :: The column of a table is known as attribute.
S1 S2 S3 S4
S5 S6 S7
Cardinality :: The number of tuples in a relation is known as
cardinality. In suppliers table, the cardinality is 5.
Degree:: The number of attributes in a relation is called degree.
In suppliers table, the degree is 4.
Component of Relation ::
Table :: Table is composed of records and fields that hold data.
Record:: Records contain all the data about one particular
person and composed of fields.
Fields:: Smallest piece of meaningful information is called field.
Data Item:: Values stored in a table are called data items.
Keys:: Key is an attribute which identifies records in a table.
There are different type of keys in RDBMS.
Primary Key :: An attribute which identifies each record in a
table is called primary key.
Table :: Student
StuId Roll No FirstName LastNmae Email
1 11 Neha Singh neha@gmail.com
2 12 Tom Andrews tom@gmail.com
3 13 Prachi Gupta prachi@gmail.com
Primary key
Candidate Key :: Candidate Key is a set of attributes that
uniquely identify tuples in a table. The Primary key should
be selected from the candidate keys. A table can have
multiple candidate keys but only a single primary key.
Candidate Key
Primary key
Alternate Key :: A Candidate key that is not the primary key
is called the Alternate key. Alternate key is also called
secondary key.
Primary key
Candidate Key
Alternate key
Foreign Key :: Foreign key is used to represent relationship
between two tables. A non key attribute of a table, which is
primary key for some other table is called foreign key. A table
that contains foreign key is called foreign table(child table or
detail table). A table that contains primary key is called foreign
table(primary table or master table).
Table:: Employee
Table:: Department
Foreign key
Primary key
Key Attribute :: Attributes that participate in the candidate
key are the key attributes.
Non Key Attribute :: Attributes other than candidate key in a
relation are called non key attributes.
Relational Algebra:: (procedural language) Relational
algebra is a collection of operations(Unary and Binary
operations)
Unary Operations :: They operate on one relation. Example ::
Select , Project
Select Operation:: Select operation is denoted by sigma(σ)
operation. Tuples are selected in select operation
σ price>14 (Items)
Consider Table :: Items
After applying the above condition in items table , following
output will be generated
Condition
Relation name
Select operation
Item# Item_Name Price
I1 Milk 15.00
I7 Icecream 16.00
I9 Namkeen 15.00
σCity=“Delhi”(Suppliers)
σPrice>5.00 ^Price<9..00 (items)
(Those tuples are selected whose price lies between 5 t0 18)
(AND sign)
(OR sign)
Supp# Supp_Name Status City
S1 Britania 10 Delhi
S3 Mother Dairy 10 Delhi
Item# Item_Name Price
I5 Plain Biscuit 6.00
I8 Cold Drink 8.00
Project Operation:: Project operation is denoted by pie(Π)
operation. Attributes are selected in project operation.
Π Supp_Name , City (Suppliers)
Consider Table :: Suppliers
After applying the above condition in Suppliers table , following
output will be generated.
Project operation
Condition
Relation name
Π City
(Suppliers)
Duplicacy is automatically removed in above query.
Supp_Name City
Britania Delhi
New Bakers Mumbai
Mothers Diary Delhi
Cookz Banglore
Haldiram Jaipur
City
Delhi
Mumbai
Banglore
Jaipur
ΠItem_Name(σPrice>14.00(Items))
Binary Operations :: They operate on two relations
Example :: Cartesian Product ,Union , Set difference , Set
intersection
Cartesian Product:: Cartesian product is denoted by X sign.
Cartesian product yields a all possible combinations of
tuples of relation A and relation B.
Item_Name
Milk
Ice Cream
Namkeen
Table :: Student
Table :: Instructor
Stud# Stud_Name Hosteler
S001 Neha Y
S002 Radha N
S003 Abhi N
Inst# Inst_Name Subject
101 K.Lal English
102 R.L Arora Maths
Cartesian Product of two relation Student X Instructor
Stud# Stud_Name Hosteler Inst# Inst_Name Subject
S001 Neha Y 101 K.Lal English
S001 Neha Y 102 R.L Arora Maths
S002 Radha N 101 K.Lal English
S002 Radha N 102 R.L Arora Maths
S003 Abhi N 101 K.Lal English
S003 Abhi N 102 R.L Arora Maths
Union Operation:: Union operation is denoted by U sign.
The resultant relation will contain all the tuples of relation A
and relation B.
Table :: Drama
Table :: Song
Roll _No Name Age
13 Kush 15
17 Swati 14
Roll _No Name Age
2 Maya 15
10 Riya 15
13 Kush 15
Drama U Song
Answer the given query on the basis of given table Customer.
(σCust_Name=Banker_Name(Customer))U(σamount>Balance(Customer))
Roll _No Name Age
2 Maya 15
10 Riya 15
13 Kush 15
17 Swati 14
Cust# Cust_Name Banker_Name Amount Balance
C001 Abju Riya 17510.00 17510.00
C002 Reeva Reeva 21000.00 22300.00
C003 Astha Neha 25199.00 24801.00
Set difference Operation:: Set difference operation is denoted by
- sign.
The resultant relation will contain those tuples that are in A but
not in relation B.
Table :: Drama
Cust# Cust_Name Banker_Name Amount Balance
C002 Reeva Reeva 21000.00 22300.00
C003 Astha Neha 25199.00 24801.00
Table :: Song
Drama – Song
Roll _No Name Age
17 Swati 14
Set intersection Operation:: Set difference operation is denoted
by n sign.
The resultant relation will contain those tuples that are common
in both relation.
Table :: Drama
Table :: Song
Drama n Song
Roll _No Name Age
13 Kush 15
DBMS (1).pptx
DBMS (1).pptx

DBMS (1).pptx

  • 2.
    DBMS :: (DataBase Management System) A DBMS refers to a s/w that is responsible for storing, maintaining and utilizing databases. DBMS is basically a record keeping system. Ex of DBMS are MS Access, MY SQL , SQL Lite, MYSQL server , Oracle , FoxPro , Dbase etc. Data Base:: Data base is defined as the organized collection of data. Ex: Attendance register , Telephone directory Need of DBMS:: Basic needs of DBMS are
  • 3.
    1.Data bases reducesdata redundancy:: Data redundancy means duplication of data. Ex: In a college, student’s records are maintained and the hostel also maintains record of all those students who live in hostel. Both college and hostel maintains a separate copy of student record. But duplication of data may lead to inconsistency. Suppose the permanent address of a hostler gets changed. The hostler student informs about it to the hostel authorities and the changed address is reflected in the student’s record. The data for the same student has not been changed in the college records. If the students forgets to inform the college authorities or college people themselves forget to update the student’s record, the same student’s record differ in two different files
  • 4.
    Now which recordof the two would be considered accurate. Suppose college has to send certain information by post. Then what will happen. The wrong data will get processed. Data bases control data inconsistency::Inconsistency means in correct information(Changes made at one place is not reflected at other place).By controlling redundancy , inconsistency can be controlled. Data base facilitate sharing of data:: Sharing of data means data in the database may be shared among several different users. Each user may have access to the data and each of them may use it for different purposes .For sharing of data grant command is used.
  • 5.
    Data bases enforcesstandards:: Data base standards are related to the naming of data , structure of data , format of data etc. Standards used in DBMS are (a). Give meaningful field name (b).Use consistent data type ie. Don’t use phone _no as numeric in one table and char in other table. Same field name in two tables should have same data type. (c). Don’t use space in table name or field name. Data base can ensure data security:: Data security means protection of data against unauthorized person. To secure database username and passwords must be applied. create user <username> identified by <password>
  • 6.
    Integrity can bemaintained through database:: Data integrity means accuracy and consistency of data. Data integrity can be maintained by various error checking and validation methods. Data validation :: Let the date format is save as dd/mm/yyyy format in SQL then date must be in dd/mm/yyyy format and not in sep 2nd 2007.This is called data validation. There are two basic rules to ensure data integrity. a). Entity Integrity :: This rule ensures that every table must have its own primary key. b). Referential Integrity :: Referential integrity is based on primary and foreign key. This rule defines that a foreign key have a matching primary key.
  • 7.
    Table:: Employee This rulestates that the Dept_id(Foreign key) in the Employee table has a matching valid Dept-id(Primary key) in the department table. Emp_id Emp_name Dept_id Table:: Department Dept_id Dept_name Dept_zone Foreign key Primary key
  • 8.
    DataBase Abstraction:: DatabaseAbstraction means to provide the users only that much information that is required by them or we can say that the system does not disclose all the details of data rather it hides certain details of how data is stored and maintained. Example :: In a bank database if a customer wants to know his balance then he is concern to only that part not even all his details that how his database is stored , where is stored and all that. Levels of Database Abstraction:: There are 3 levels of database implementation. 1. Internal level 2. Conceptual level 3. External level
  • 9.
    Internal level ::Internal level is also called physical level or storage level. It describes how data are actually stored in the storage medium. Conceptual level :: Conceptual level is also called logical level. It describes what data are actually stored in the database. This level is related to the structure of the database. External level :: External level is also called view level. It describes the way in which the data are viewed by the users. Most of the users of the database are not concerned with all the information contained in the database. Instead, they need only a part of the database relevant to them.
  • 10.
    Sales officer (T1) Itemname price Purchase officer (T2) Item name Quatity Item_no integer Item_name char(10) Price integer Quantity integer Item_no type=byte(38),offset=5 Item_name type=byte(38),offset=7 Price type=byte(38),offset=36 Quantity type=byte(34),offset=15 pPhysical Level
  • 11.
    Concept of DataIndependance:: The ability to modify a scheme definition in one level without affecting the scheme definition in the next higher level is called Data Independence. There are two levels of data independence. 1) Physical data independence 2) Logical data independence Physical data independence:: Modify the scheme followed at the physical level without affecting the scheme followed at the conceptual level. Any of the below change in physical level will not affect the conceptual level. Using a new storage device like Hard Drive or Magnetic Tapes. Change of Location of Database from say C drive to D Drive
  • 12.
    Logical data independence::Modify the scheme followed at the conceptual level without affecting the scheme followed at the external level. Any of the below change in conceptual level will not affect the external level. Add/Modify/Delete a new attribute Merging two records into one Breaking an existing record into two or more records
  • 13.
    Data Models ::Data models are basically concepts that can be used to describe the structure of a database .The three data models are used in database management system. Relational data model Network data model Hierarchical data model 1.Relational data model:: In relational data model data is organized in the form of tables. These tables are called relations. Relationship b/w record is represented by relation containing keys. Let there are three tables(relations) Suppliers , Items , Shipments Unit 3.2 Relational Data Model
  • 15.
    Rows in arelation are generally referred to as tuples and columns in a relation are generally referred to as attributes. 2.Network data model:: In Network data model data is organized in the form of graph structure. Relationship b/w record is represented by links.
  • 16.
    3.Hierarchical data model::In Hierarchical data model data is organized in the form of trees. Relationship b/w record is represented by trees(parent child form). Root
  • 17.
  • 18.
    Relational Data Models:: Relational data model was developed by E.F Codd. In this model data is organised in two dimensional table called relation. Basic terms used in Relational database :: Entity :: Name of the table Relation :: Relation is a table , consists of tuples (rows) and attributes(columns).A relation must have following properties. An item in a given column are of same kind. All rows of relation must be distinct Column name of a relation are assigned distinct names.
  • 19.
     Each rowmust be uniquely identified Domain :: A domain is a pool of values from which actual values appearing in a given column are drawn. Suppno is drawn from above domain in “suppliers” table. Tuple:: The row of a table is known as tuple. Attribute :: The column of a table is known as attribute. S1 S2 S3 S4 S5 S6 S7
  • 20.
    Cardinality :: Thenumber of tuples in a relation is known as cardinality. In suppliers table, the cardinality is 5. Degree:: The number of attributes in a relation is called degree. In suppliers table, the degree is 4. Component of Relation :: Table :: Table is composed of records and fields that hold data. Record:: Records contain all the data about one particular person and composed of fields. Fields:: Smallest piece of meaningful information is called field.
  • 21.
    Data Item:: Valuesstored in a table are called data items. Keys:: Key is an attribute which identifies records in a table. There are different type of keys in RDBMS. Primary Key :: An attribute which identifies each record in a table is called primary key. Table :: Student StuId Roll No FirstName LastNmae Email 1 11 Neha Singh neha@gmail.com 2 12 Tom Andrews tom@gmail.com 3 13 Prachi Gupta prachi@gmail.com Primary key
  • 22.
    Candidate Key ::Candidate Key is a set of attributes that uniquely identify tuples in a table. The Primary key should be selected from the candidate keys. A table can have multiple candidate keys but only a single primary key. Candidate Key Primary key
  • 23.
    Alternate Key ::A Candidate key that is not the primary key is called the Alternate key. Alternate key is also called secondary key. Primary key Candidate Key Alternate key
  • 24.
    Foreign Key ::Foreign key is used to represent relationship between two tables. A non key attribute of a table, which is primary key for some other table is called foreign key. A table that contains foreign key is called foreign table(child table or detail table). A table that contains primary key is called foreign table(primary table or master table). Table:: Employee Table:: Department Foreign key Primary key
  • 25.
    Key Attribute ::Attributes that participate in the candidate key are the key attributes. Non Key Attribute :: Attributes other than candidate key in a relation are called non key attributes. Relational Algebra:: (procedural language) Relational algebra is a collection of operations(Unary and Binary operations) Unary Operations :: They operate on one relation. Example :: Select , Project Select Operation:: Select operation is denoted by sigma(σ) operation. Tuples are selected in select operation
  • 26.
    σ price>14 (Items) ConsiderTable :: Items After applying the above condition in items table , following output will be generated Condition Relation name Select operation Item# Item_Name Price I1 Milk 15.00 I7 Icecream 16.00 I9 Namkeen 15.00
  • 27.
    σCity=“Delhi”(Suppliers) σPrice>5.00 ^Price<9..00 (items) (Thosetuples are selected whose price lies between 5 t0 18) (AND sign) (OR sign) Supp# Supp_Name Status City S1 Britania 10 Delhi S3 Mother Dairy 10 Delhi Item# Item_Name Price I5 Plain Biscuit 6.00 I8 Cold Drink 8.00
  • 28.
    Project Operation:: Projectoperation is denoted by pie(Π) operation. Attributes are selected in project operation. Π Supp_Name , City (Suppliers) Consider Table :: Suppliers After applying the above condition in Suppliers table , following output will be generated. Project operation Condition Relation name
  • 29.
    Π City (Suppliers) Duplicacy isautomatically removed in above query. Supp_Name City Britania Delhi New Bakers Mumbai Mothers Diary Delhi Cookz Banglore Haldiram Jaipur City Delhi Mumbai Banglore Jaipur
  • 30.
    ΠItem_Name(σPrice>14.00(Items)) Binary Operations ::They operate on two relations Example :: Cartesian Product ,Union , Set difference , Set intersection Cartesian Product:: Cartesian product is denoted by X sign. Cartesian product yields a all possible combinations of tuples of relation A and relation B. Item_Name Milk Ice Cream Namkeen
  • 31.
    Table :: Student Table:: Instructor Stud# Stud_Name Hosteler S001 Neha Y S002 Radha N S003 Abhi N Inst# Inst_Name Subject 101 K.Lal English 102 R.L Arora Maths
  • 32.
    Cartesian Product oftwo relation Student X Instructor Stud# Stud_Name Hosteler Inst# Inst_Name Subject S001 Neha Y 101 K.Lal English S001 Neha Y 102 R.L Arora Maths S002 Radha N 101 K.Lal English S002 Radha N 102 R.L Arora Maths S003 Abhi N 101 K.Lal English S003 Abhi N 102 R.L Arora Maths
  • 33.
    Union Operation:: Unionoperation is denoted by U sign. The resultant relation will contain all the tuples of relation A and relation B. Table :: Drama Table :: Song Roll _No Name Age 13 Kush 15 17 Swati 14 Roll _No Name Age 2 Maya 15 10 Riya 15 13 Kush 15
  • 34.
    Drama U Song Answerthe given query on the basis of given table Customer. (σCust_Name=Banker_Name(Customer))U(σamount>Balance(Customer)) Roll _No Name Age 2 Maya 15 10 Riya 15 13 Kush 15 17 Swati 14 Cust# Cust_Name Banker_Name Amount Balance C001 Abju Riya 17510.00 17510.00 C002 Reeva Reeva 21000.00 22300.00 C003 Astha Neha 25199.00 24801.00
  • 35.
    Set difference Operation::Set difference operation is denoted by - sign. The resultant relation will contain those tuples that are in A but not in relation B. Table :: Drama Cust# Cust_Name Banker_Name Amount Balance C002 Reeva Reeva 21000.00 22300.00 C003 Astha Neha 25199.00 24801.00
  • 36.
    Table :: Song Drama– Song Roll _No Name Age 17 Swati 14
  • 37.
    Set intersection Operation::Set difference operation is denoted by n sign. The resultant relation will contain those tuples that are common in both relation. Table :: Drama Table :: Song
  • 38.
    Drama n Song Roll_No Name Age 13 Kush 15