Dbms Notes
Dbms Notes
➢ From the earliest days of computer storing and manipulating data have been a
major application.
➢ The first general purpose DBMS designed by “Charles Bachman ”at general
electric in 1960’s was called “Integrated Data Store”.
➢ Charles Bachman is the first person to develop the IDS( Integrared Data
Store).which was based on network model.
➢ In the late 1960’s IBM developed the “ Integrated Management Systems “
➢ In 1970’s the “ Relational Data Base model “ was developed by “ Edgar Codd “
at IBM.
➢ Many of the data base models we use today are Relational based.
➢ It was developed as a standard language for the queries by ISO and ANSI .
1990s:
2000s:
➢ Integrity problems
Example: Transfer of funds from one account to another should either complete
or not happen at all
➢ Security problems.
➢ File system is used to manage the data , dbms is also used to manage the data
➢ File systems are for short amount of data as well as Dbms will consists huge data
➢ File : A collection of records , where records contains fields, where field contains data
➢ Data Inconsistency :Because of data redundancy , data inconsistency problem will occurs.
(no accurate data)
➢ Data Isolation : when data of a file cannot be mapped with the related data of other file
➢ Atomicity Issues : If the transaction involves two operations then we have to execute those
two operations at once in order to complete the transaction..
➢ Data security :
File system vs DBMS
FILE SYSTEM DBMS
File system is a software that manages DBMS is a software for managing the data
and organizes the files in a storage with in base
a computer
There is no redundant data
Redundant data can be present in a file
system
It doesn't provide backup and recovery of It provides backup and recovery of data if
data if it is lost it is lost
There is no efficient query processing in a Efficient query processing is there in DBMS
file system
There is less data consistency in file
systems There is more data consistency because of
the process of normalization
It is less complex when compared to DBMS
It has more complexity
File system provides less security in
compared to DBMS DBMS has more security Mechanisms
➢ Telecommunications Military
➢ Online retailers
➢ it is a data model in which the data is organized in the form of TREE structure
➢ The structure represents information using parent – child relation ship
➢ Here each parent can have many children and child has only single parent.
➢ That is one to many relation ship
Advantages :
➢ complex implementation
➢ Difficult to manage
➢ Structured dependency
➢ It doesn’t support many to many relationship
➢ In a network data model one parent can have several children and a child can have
many parent records.
➢ It follows GRAPH structure
➢ Network model is extension to hierarchical data model.
Advantages :
Disadvantages :
➢ As more and more relationships need to be handled the system might get complex
Entity relationship model:
It contains mainly three things
1.Entity
2.Attibutes
3.Relationships.
1.Entity :
➢ Any real world thing , any thing that has physical existence is called entity
Example : student , faculty,…
2.Attributes :
3.Reltionships:
➢ Relationship is manly use in order to connect two entities
1.one to one relationship 2. one to many relationship
3.many to one relationship 4.many to many relatioship
E-R Diagram for the Banking Enterprise
Features of ER Model:
➢ Graphical design for better understanding : It is very easy to understand so it can be
used by the developers
➢ Database design: This model helps the database designers to build the database
➢ ER Diagram :ER Diagram is used as a visual tool for representing the model.
Advantages of ER Model:
Disadvantages of ER Model :
ATTRIBUTES
➢ Simple : This model is more simple as compared to the network and hierarchical model.
➢ Scalable : This model can be easily scaled as we can add as many rows and columns we want.
➢ For hiding the complexities and making things easier for the use this model requires more
powerful hardware computers and storage devices.
➢ As the relational model is very easy to design and use.
➢ In this model both the data and relationship are present in a single structure known as object.
➢ We can store audio ,video ,images ,etc in the database which is not possible in the Relational
model
➢ Although you can store audio and video in relational database , it is advised not to store in the
relational database.
➢ In this model, the attributes describe the properties of an object.
➢ Object that share similar characteristics are grouped in classes.
➢ Therefore, a class is a collection of similar objects model, two or more objects are
connected with the help of links.
➢ We use the link to relate objects.
For example:
EMPLOYEE DEPARTMENT
ATTRIBUTES ATTRIBUTES
NAME DEPT_ID
PHONE NO. DEPT_NAME
SALARY METHODS
DEPT_ID Change department
METHODS
Change number
➢ There are two data objects in the above example :
1.Employee
2.Department
Advantages:
Disadvantages :
➢ it is complex navigation system
➢ Slow development of standards
➢ High system overheads
➢ Slow transactions.
LEVELS OF ABSTRACTON :
➢ Data abstraction is the process of hiding unwanted or irrelevant details from the end user
➢ The database system consists of complicated data structures and relation.
➢ For users to access the data easily, these complications are kept hidden, and only the
relevant part of the database is made accessible to the users through the data abstraction.
VIEW LEVEL
VIEW 1 ….
VIEW2 VIEW N
LOGICAL
LEVEL
PHYSICAL
LEVEL
Physical level:
Logical level:
View level :
Instances :
(OR)
➢ The content of the database at a given point of time
➢ It is a dynamic value which keeps on changing.
ROLL NO NAME MARKS
➢ For ex: student table.
100 RAJU 90
101 RAMESH 85
102 MAHESH 95
This table contains 3 row i.e. instance of the table or instance of database
Schema :
➢ If we change data or data structure in the database it will not modify the user
level instructions.(or) the ability to change the schema at one level without
changing the schema at another level is known as data independence.
➢ If we change the data in the database these changes will not reflect above
levels of logical and view level
❖ Note That: structure of Database management system is also referred as overall system structure
or Database Architecture but is different from the Tier Architecture of Database.
1.Query Processer
2. Storage Manager
3.Disk Storage
ER DIAGRAMS
➢ The entity relationship diagram explains the relationship among the entities present in the
Database.
➢ ER models are used to model real world objects like a person, a car, a company, and the
relation between these real world objects.
➢ ER diagrams are used to represent the E-R model in a database, which make them easy to
Convert into relations(Tables).
➢ ER diagrams require no technical knowledge and no hardware support
➢ These diagrams are very easy to understand and easy to create even for a naïve user.
Attributes in ER Model
ELLIPSE
Relationship Among
DIAMOND Attributes
ER MODEL:
1.Entity.
❑ Strong Entity
❑ Weak Entity
2. Attributes.
❑ Key Attributes
❑ Composite Attributes
❑ Multivalued Attributes
❑ Derived Attributes
❑ Simple Attribute.
❑ Single Valued Attributes.
Relationship:
❑ One to One
❑ One to Many
❑ Many to One
❑ Many to Many
Entity :
An Entity may be an object with a physical existence – a particular person, car, house, or employee – or it may
be an object with a conceptual existence – a company, a job, or a university course.
Entity Set:
An Entity is an object of Entity Type and a set of all entities is called an entity set.
For Example, E1 is an entity having Entity Type Student and the set of all students is called Entity Set.
In ER diagram.
Entity Type is represented as:
1.Strong Entity:
2. Weak Entity :
➢ An Entity type has a key attribute that uniquely identifies each entity in the entity set.
➢ But some entity type exists for which key attributes can’t be defined.
➢ These are called Weak Entity types.
For Example:
▪ A company may store the information of dependents (Parents, Children, Spouse) of an Employee.
But the dependents don’t have existed without the employee.
▪ So Dependent will be a Weak Entity Type and Employee will be Identifying Entity type for Dependent,
which means it is Strong Entity Type.
➢ A weak entity type is represented by a Double Rectangle.
➢ The participation of weak entity types is always total.
➢ The relationship between the weak entity type and its identifying strong entity type is called
identifying relationship and it is represented by a double diamond.
Attributes:
➢ Attributes are the properties that define the entity type.
For example, RollNo, Name, DOB, Age, Address, and MobileNo are the attributes that define entity type Student.
➢ In ER diagram, the attribute is represented by an oval.
1. Key Attribute :
➢ The attribute which uniquely identifies each entity in the entity set is called the key attribute.
➢ For example, Roll_No will be unique for each student.
➢ In ER diagram, the key attribute is represented by an oval with underlying lines.
2. Composite Attribute :
➢ An attribute that can be derived from other attributes of the entity type is known
as a derived attribute. e.g.; Age (can be derived from DOB).
➢ In ER diagram, the derived attribute is represented by a dashed oval.
The Complete Entity Type Student with its Attributes can be represented as:
Relationship Type and Relationship Set :
Relationship Set
Degree of a Relationship Set :
The number of different entity sets participating in a relationship set is called the degree of a relationship set.
1. Unary Relationship:
➢ When there is only ONE entity set participating in a relation,
the relationship is called a unary relationship.
➢ For example, one person is married to only one person.
2. Binary Relationship:
➢ When there are TWO entities set participating in a relationship, the relationship is called a
binary relationship.
➢ For example, a Student is enrolled in a Course.
1. One-to-One:
➢ When each entity in each entity set can take part only once in the relationship, the cardinality is one-to-one.
➢ Let us assume that a male can marry one female and a female can marry one male.
➢ So the relationship will be one-to-one.
➢ the total number of tables that can be used in this is 2.
➢ In one-to-many mapping as well where each entity can be related to more than
one relationship and the total number of tables that can be used in this is 2.
➢ When entities in one entity set can take part only once in the relationship set and entities in other
entity sets can take part more than once in the relationship set, cardinality is many to one.
➢ Let us assume that a student can take only one course but one course can be taken by many
students.
➢ It means that for one course there can be n students but for one student, there will be only one
course.
➢ Generalization, Specialization, and Aggregation in ER model are used for data abstraction.
➢ in which an abstraction mechanism is used to hide details of a set of objects.
➢ Some of the terms were added to the Enhanced ER Model,
➢ where some new concepts were added.
1.Generalization:
➢ Generalization is the process of extracting common properties from a set of entities and
creating a generalized entity from it.
➢ It is a bottom-up approach in which two or more entities can be generalized to a higher-level entity
if they have some attributes in common.
➢ For Example, STUDENT and FACULTY can be generalized to a higher-level entity called PERSON as shown in
Figure
➢ In this case, common attributes like P_NAME, and P_ADD become part of a higher ENTITY (PERSON),
and specialized ATTRIBUTES like S_FEE become part of a specialized entity (STUDENT).
Generalization
Specialization:
➢ In specialization, an entity is divided into sub-entities based on its characteristics.
➢ It is a top-down approach where the higher-level entity is specialized into two or more lower-
level entities.
➢ For Example, an EMPLOYEE entity in an Employee management system can be specialized into
DEVELOPER, TESTER, etc. as shown in Figure 2.
➢ In this case, common attributes like E_NAME, E_SAL, etc. become part of a higher entity
(EMPLOYEE), and specialized attributes like TES_TYPE become part of a specialized entity
(TESTER).
Aggregation:
➢ An ER diagram is not capable of representing the relationship between an
entity and a relationship which may be required in some scenarios.
➢ They allow you to find the relation between two tables. Keys help you uniquely
identify a row in a table by a combination of one or more columns in that table.
➢ Key is also helpful for finding unique record or row from the table. Database
key is also helpful for finding unique record or row from the table.
➢ In this table, no other employee can have the same employee ID.
Why we need a Key?
➢ Here are some reasons for using sql key in the DBMS system.
➢ Keys help you to identify any row of data in a table. In a real-world application, a table
could contain thousands of records. Moreover, the records could be duplicated.
➢ Keys in RDBMS ensure that you can uniquely identify a table record despite these
challenges.
➢ Allows you to establish a relationship between and identify the relation between tables.
➢ There are mainly Eight different types of Keys in DBMS and each key has it’s different
functionality:
1.Super Key
2.Primary Key
3.Candidate Key
4.Alternate Key
5.Foreign Key
6.Compound Key
7.Composite Key
8.Surrogate Key
Super Key – A super key is a group of single or multiple keys which identifies rows in a table.
Primary Key – is a column or group of columns in a table that uniquely identify every row in that table.
Candidate Key – is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with
no repeated attributes.
Alternate Key – is a column or group of columns in a table that uniquely identify every row in that table.
Foreign Key – is a column that creates a relationship between two tables. The purpose of Foreign keys is to
maintain data integrity and allow navigation between two different instances of an entity.
Compound Key – has two or more attributes that allow you to uniquely recognize a specific record. It is possible
that each column may not be unique by itself within the database.
Composite Key – is a combination of two or more columns that uniquely identify rows in a table. The
combination of columns guarantees uniqueness, though individual uniqueness is not
guaranteed.
Surrogate Key – An artificial key which aims to uniquely identify each record is called a surrogate key. These
kind of key are unique because they are created when you don’t have any natural primary key.
What is the Super key?
➢ A super key is a group of single or multiple keys which identifies rows in a table.
➢ A Super key may have additional attributes that are not needed for unique
identification.
Example:
➢ ALTERNATE KEYS is a column or group of columns in a table that uniquely identify every row in that
table.
➢ A table can have multiple choices for a primary key but only one can be set as the primary key.
➢ All the keys which are not primary key are called an Alternate Key.
Example:
➢ In this table, StudID, Roll No, Email are qualified to become a primary key.
➢ But since StudID is the primary key, Roll No, Email becomes the alternative key.
➢ CANDIDATE KEY in SQL is a set of attributes that uniquely identify tuples in a table.
➢ A table can have multiple candidate keys but only a single primary key.
Example:
DeptCode DeptName
001 Science
002 English
005 Computer
➢ In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship
between the two tables.
➢ COMPOUND KEY has two or more attributes that allow you to uniquely recognize a specific record.
➢ It is possible that each column may not be unique by itself within the database.
➢ However, when combined with the other column or columns the combination of composite keys become
unique.
➢ The purpose of the compound key in database is to uniquely identify each record in the table.
Example:
➢ In this example, OrderNo and ProductID can’t be a primary key as it does not uniquely identify a record.
➢ However, a compound key of Order ID and Product ID could be used as it uniquely identified each record.
.
What is the Composite key?
➢ COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table.
➢ The combination of columns guarantees uniqueness, though individually uniqueness is not guaranteed.
➢ Hence, they are combined to uniquely identify records in a table.
➢ The difference between compound and the composite key is that any part of the compound key can be a foreign
key, but the composite key may or maybe not a part of the foreign key.
➢ SURROGATE KEYS is an artificial key which aims to uniquely identify each record is called a surrogate key.
➢ This kind of partial key in dbms is unique because it is created when you don’t have any natural primary key.
➢ They do not lend any meaning to the data in the table.
➢ Surrogate key in DBMS is usually an integer.
➢ A surrogate key is a value generated right before the record is inserted into a table.
Primary Key never accept null A foreign key may accept multiple
null values.
values.
Generalization is the higher level of understanding of data from lower levels of data whereas
Specialization is the process of defining one or more entities from present entities and Aggregation is the
process of combining two or more entities.
Generalization is simply gathering the common properties from entities and creating a generalized
concept from those extracted data. Generalization helps in improving the flexibility, and reusability of
the database.
Generalization is important in the database because it helps to gather important information so that it
becomes easier and faster for the user the analysis of data and it also helps in making decisions faster.
UNIT -II
Integrity Constraints:
➢ Integrity constraints are a set of rules. It is used to maintain the quality of information.
➢ Integrity constraints ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected.
➢ Thus, integrity constraint is used to guard against accidental damage to the database.
➢ The data type of domain includes string, character, integer, time, date, currency, etc.
Example:
2. Entity integrity constraints:
➢ The entity integrity constraint states that primary key value can't be null.
➢ This is because the primary key value is used to identify individual rows in relation and if the primary
key has a null value, then we can't identify those rows.
➢ A table can contain a null value other than the primary key field.
Example:
3. Referential Integrity Constraints :
➢ In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2, then
every value of the Foreign Key in Table 1 must be null or be available in Table 2.
Example:
4. Key constraints :
➢ Keys are the entity set that is used to identify an entity within its entity set uniquely.
➢ An entity set can have multiple keys, but out of which one key will be the primary key. A primary key can
contain a unique and null value in the relational table.
Example: