DBMS Unit 1
DBMS Unit 1
INTRODUCTION:
DDL is the short name for Data Definition Language, which deals with
database schemas and descriptions, of how the data should reside in the
database.
CREATE: to create a database and its objects like (table, index,
views, store procedure, function, and triggers)
ALTER: alters the structure of the existing database
DROP: delete objects from the database
TRUNCATE: remove all records from a table, including all spaces
allocated for the records are removed
COMMENT: add comments to the data dictionary
RENAME: rename an object
DML is the short name for Data Manipulation Language which deals with
data manipulation and includes most common SQL statements such
SELECT, INSERT, UPDATE, DELETE, etc., and it is used to store,
modify, retrieve, delete and update data in a database.
SELECT: retrieve data from a database
INSERT: insert data into a table
UPDATE: updates existing data within a table
DELETE: Delete all records from a database table
MERGE: UPSERT operation (insert or update)
CALL: call a PL/SQL or Java subprogram
EXPLAIN PLAN: interpretation of the data access path
LOCK TABLE: concurrency Control
Data Independence
Data independence means a change of data at one level should not
affect another level. Two types of data independence are present in this
architecture:
1. Physical Data Independence: Any change in the physical location of
tables and indexes should not affect the conceptual level or external
view of data. This data independence is easy to achieve and
implemented by most of the DBMS.
2. Conceptual Data Independence: The data at conceptual level
schema and external level schema must be independent. This means
a change in conceptual schema should not affect external schema.
e.g.; Adding or deleting attributes of a table should not affect the
user’s view of the table. But this type of independence is difficult to
achieve as compared to physical data independence because the
changes in conceptual schema are reflected in the user’s view.
Only one user can access data at a Multiple users can access
User Access time. data at a time.
The user has to write procedures for The user not required to
Meaning managing databases write procedures.
Introduction of ER Model
The Entity Relational Model is a model for identifying entities to be
represented in the database and representation of how those entities are
related. The ER data model specifies enterprise schema that represents
the overall logical structure of a database graphically.
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, or a company and the relation between these
real-world objects. In short, ER Diagram is the structural format of the
database.
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among
Entities in a Database System.
Entity
Attributes
Attributes are the properties that define the entity type. For example,
Roll_No, Name, DOB, Age, Address, and Mobile_No 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 composed of many other attributes is called a composite
attribute. For example, the Address attribute of the student Entity type
consists of Street, City, State, and Country. In ER diagram, the composite
attribute is represented by an oval comprising of ovals.
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For
example, Phone_No (can be more than one for a given student). In ER
diagram, a multivalued attribute is represented by a double oval.
4. Derived 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
A Relationship Type represents the association between entity types. For
example, ‘Enrolled in’ is a relationship type that exists between entity type
Student and Course. In ER diagram, the relationship type is represented
by a diamond and connecting the entities with lines.
A set of relationships of the same type is known as a relationship set. The
following relationship set depicts S1 as enrolled in C2, S2 as enrolled in
C1, and S3 as registered in C3.
Cardinality
The number of times an entity of an entity set participates in a
relationship set is known as cardinality. Cardinality can be of different
types:
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.
3. Many-to-One: 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. So the cardinality will be n to 1. It means that for
one course there can be n students but for one student, there will be only
one course.
The total number of tables that can be used in this is 3.
Using Sets, it can be represented as:
In this case, each student is taking only 1 course but 1 course has
been taken by many students.
4. Many-to-Many: When entities in all entity sets can take part more than
once in the relationship cardinality is many to many. Let us assume that a
student can take more than one course and one course can be taken by
many students. So the relationship will be many to many.
the total number of tables that can be used in this is 3.
Example:
STUD_NO is the candidate key for relation STUDENT.
Table STUDENT
STUD_NO SNAME ADDRESS PHONE
2. Primary Key: There can be more than one candidate key in relation
out of which one can be chosen as the primary key. For Example,
STUD_NO, as well as STUD_PHONE, are candidate keys for relation
STUDENT but STUD_NO can be chosen as the primary key (only one
out of many candidate keys).
It is a unique key.
It can identify only one tuple (a record) at a time.
It has no duplicate values, it has unique values.
It cannot be NULL.
Primary keys are not necessarily to be a single column; more than one
column can also be a primary key for a table.
Example:
STUDENT table -> Student(STUD_NO, SNAME,
ADDRESS, PHONE) , STUD_NO is a primary key
Table STUDENT
STUD_NO SNAME ADDRESS PHONE
3. Super Key: The set of attributes that can uniquely identify a tuple is
known as Super Key. For Example, STUD_NO, (STUD_NO,
STUD_NAME), etc. A super key is a group of single or multiple keys that
identifies rows in a table. It supports NULL values.
Adding zero or more attributes to the candidate key generates the
super key.
A candidate key is a super key but vice versa is not true.
Example:
Consider the table shown above.
STUD_NO+PHONE is a super key.
Generalization
Generalization is a process of generalizing an entity which contains generalized
attributes or properties of generalized entities. The entity that is created will
contain the common features. Generalization is a Bottom up process.
We can have three sub entities as Car, Truck, Motorcycle and these
three entities can be generalized into one general super class as Vehicle.
Specialization
Specialization is a process of identifying subsets of an entity that shares different
characteristics. It breaks an entity into multiple entities from higher level (super
class) to lower level (sub class). The breaking of higher level entity is based on
some distinguishing characteristics of the entities in super class.
It is a top down approach in which we first define the super class and then sub
class and then their attributes and relationships.
Aggregation
Aggregation represents relationship between a whole object and its component.
Using aggregation we can express relationship among relationships.
Aggregation shows ‘has-a’ or ‘is-part-of’ relationship between entities where one
represents the ‘whole’ and other ‘part’.