Dbms Unit1
Dbms Unit1
Dbms Unit1
Unit One
Attiuttama Mishra
Asst. Prof.
DBMS - Overview
Data Isolation: Because data are scattered in various files, and files may be
in different formats, writing new application programs to retrieve the
appropriate data is difficult.
Duplication of data – Redundant data
Dependency on application programs – Changing files would lead to
change in application programs.
It allows access to single files or tables at a time. FMS’s accommodate flat
files that have no relation to other files.
Advantage of DBMS over file system
The DBMS design depends upon its architecture. The basic client/server
architecture is used to deal with a large number of PCs, web servers, database
servers and other components that are connected with networks.
The client/server architecture consists of many PCs and a workstation which
are connected via the network.
2-Tier Architecture-
The 2-Tier architecture is same as basic client-server. In the two-tier
architecture, applications on the client end can directly communicate with
the database at the server side. For this interaction, API's
like: ODBC, JDBC are used.
The user interfaces and application programs are run on the client-side.
The server side is responsible to provide the functionalities like: query
processing and transaction management.
To communicate with the DBMS, client-side application establishes a
connection with the server side.
Fig: 2-tier Architecture
3-Tier Architecture-
2. Conceptual Level
•The conceptual schema describes the design of a database at the
conceptual level. Conceptual level is also known as logical level.
•The conceptual schema describes the structure of the whole database.
•The conceptual level describes what data are to be stored in the database
and also describes what relationship exists among those data.
•In the conceptual level, internal details such as an implementation of the
data structure are hidden.
•Programmers and database administrators work at this level.
3. External Level
•At the external level, a database contains several schemas that sometimes
called as subschema. The subschema is used to describe the different view of
the database.
•An external schema is also known as view schema.
•Each view schema describes the database part that a particular user group is
interested and hides the remaining database from that user group.
•The view schema describes the end user interaction with database systems.
Data Independence
•The data which is stored in the database at a particular moment of time is called
an instance of the database.
•The overall design of a database is called schema.
•A database schema is the skeleton structure of the database. It represents the
logical view of the entire database.
•A schema contains schema objects like table, foreign key, primary key, views,
columns, data types, stored procedure, etc.
•A database schema can be represented by using the visual diagram. That
diagram shows the database objects and relationship with each other.
For example: In the following diagram, we have a schema that shows the
relationship between three tables: Course, Student and Grade. It does not
show all aspects of database.
Example of Instance
For example, lets say we have a single table student in the database, today the table
has 100 records, so today the instance of the database has 100 records. Lets say we
are going to add another 100 records in this table by tomorrow so the instance of
database tomorrow will have 200 records in table. In short, at a particular moment
the data stored in database is called the instance, that changes over time when we
add or delete data from the database.
View of Data in DBMS/Data Abstraction
Data Abstraction is one of the main features of database systems. Hiding irrelevant
details from user and providing abstract view of data to users, helps in easy and
efficient user-database interaction.
The view level provides the “view of data” to the users and hides the irrelevant details
such as data relationship, database schema, constraints, security etc from the user.
Database Language
•A DBMS has appropriate languages and interfaces to express database
queries and updates.
•Database languages can be used to read, store and update the data in the
database.
A Database model defines the logical design and structure of a database and
defines how data will be stored, accessed and updated in a database
management system. While the Relational Model is the most widely used
database model, there are other models too:
•Hierarchical Model
•Network Model
•Entity-relationship Model
•Relational Model
Hierarchical Model
If the attributes are composite, they are further divided in a tree like
structure. Every node is then connected to its attribute. That is,
composite attributes are represented by ellipses that are connected with
an ellipse.
Multivalued attributes are depicted by
double ellipse.
Example??
One-to-many − When more than one instance of an entity is
associated with a relationship, it is marked as '1:N'.
Examples??
ER diagram
Weak Entity And Strong Entity:
The Weak entity that cannot be uniquely identified by its own attributes and
relies on the relationship with other entity is called weak entity. The weak
entity is represented by a double rectangle.
The Strong Entity is the one whose existence does not depend on the
existence of any other entity in a schema. It is denoted by a single rectangle.
A strong entity always has the primary key .
For example-the ER-diagram above, for each loan, there should be at least
one borrower otherwise that loan would not be listed in Loan entity set. But
even if a customer does not borrow any loan it would be listed in Customer
entity set. So we can conclude that a customer entity does not depend on a
loan entity.
E R notations
Data Generalization
Generalization Example
Lets say we have two
entities Student and
Teacher.
Attributes of Entity Student
are: Name, Address & Grade
Attributes of Entity Teacher
are: Name, Address & Salary
These two entities have two common attributes: Name and Address,
we can make a generalized entity with these common attributes.
Note:
1. Generalization uses bottom-up approach where two or more lower level
entities combine together to form a higher level new entity.
2. The new generalized entity can further combine together with lower level
entity to create a further higher level generalized entity.
Data Specialization
Types of constraints
NOT NULL
UNIQUE
DEFAULT
CHECK
Key Constraints – PRIMARY KEY, FOREIGN KEY
Domain constraints
Mapping constraints
NOT NULL:
NOT NULL constraint makes sure that a column does not hold NULL value.
When we don’t provide value for a particular column while inserting a
record into a table, it takes NULL value by default. By specifying NULL
constraint, we can be sure that a particular column(s) cannot have NULL
values.
Example:
CREATE TABLE STUDENT( ROLL_NO INT NOT NULL,
STU_NAME VARCHAR (35) NOT NULL,
STU_AGE INT NOT NULL,
STU_ADDRESS VARCHAR (235),
PRIMARY KEY (ROLL_NO) );
UNIQUE:
UNIQUE Constraint enforces a column or set of columns to have unique values. If a
column has a unique constraint, it means that particular column cannot have
duplicate values in a table.
DEFAULT:
The DEFAULT constraint provides a default value to a column when there is no value
provided while inserting a record into a table.
Primary key uniquely identifies each record in a table. It must have unique values and
cannot contain nulls. In the below example the ROLL_NO field is marked as primary
key, that means the ROLL_NO field cannot have duplicate and null values.
FOREIGN KEY:
Foreign keys are the columns of a table that points to the primary key of another
table. They act as a cross-reference between tables.
Domain constraints:
Each table has certain set of columns and each column allows a same type of data,
based on its data type. The column does not accept values of any other data type
.
Domain constraints are user defined data type and we can define them like this:
Domain Constraint = data type + Constraints (NOT NULL / UNIQUE / PRIMARY KEY /
FOREIGN KEY / CHECK / DEFAULT)
Mapping constraints:
Mapping Cardinality: :
One to One: An entity of entity-set A can be associated with at most one entity of
entity-set B and an entity in entity-set B can be associated with at most one entity of
entity-set A.
One to Many: An entity of entity-set A can be associated with any number of entities of
entity-set B and an entity in entity-set B can be associated with at most one entity of
entity-set A.
Many to One: An entity of entity-set A can be associated with at most one entity of
entity-set B and an entity in entity-set B can be associated with any number of entities
of entity-set A.
Many to Many: An entity of entity-set A can be associated with any number of entities
of entity-set B and an entity in entity-set B can be associated with any number of
entities of entity-set A.
How to draw a basic ER diagram
Purpose and scope: Define the purpose and scope of what you’re analyzing or
modeling.
Entities: Identify the entities that are involved. When you’re ready, start drawing them
in rectangles (or your system’s choice of shape) and labeling them as nouns.
Relationships: Determine how the entities are all related. Draw lines between them to
signify the relationships and label them. Some entities may not be related, and that’s fine.
In different notation systems, the relationship could be labeled in a diamond, another
rectangle or directly on top of the connecting line.
Attributes: Layer in more detail by adding key attributes of entities. Attributes are often
shown as ovals.
Cardinality: Show whether the relationship is 1-1, 1-many or many-to-many.
Some examples of ER-Diagrams
Limitations of ER diagrams and models
Only for relational data: Understand that the purpose is to show relationships. ER
diagrams show only that relational structure.
Not for unstructured data: Unless the data is cleanly delineated into different fields,
rows or columns, ER diagrams are probably of limited use. The same is true of semi-
structured data, because only some of the data will be useful.
Difficulty integrating with an existing database: Using ER Models to integrate with
an existing database can be a challenge because of the different architectures.
No representation of data manipulation: It is difficult to show data manipulation in
ER model.
KEYS
•Keys play an important role in the relational database.
•It is used to uniquely identify any record or row of data from the table. It is
also used to establish and identify relationships between tables.
Primary key
•It is the first key used to identify one and only one instance of an entity
uniquely. An entity can contain multiple keys, as we saw in the PERSON
table. The key which is most suitable from those lists becomes a primary key.
2. Candidate key
•A candidate key is an attribute or set of attributes that can uniquely identify
a tuple.
•Except for the primary key, the remaining attributes are considered a
candidate key. The candidate keys are as strong as the primary key.
•For example: In the EMPLOYEE table, id is best suited for the primary key. The rest
of the attributes, like SSN, Passport_Number, License_Number, etc., are considered
a candidate key.
3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a
superset of a candidate key.