DBMS Exam Oriented - 1
DBMS Exam Oriented - 1
MODULE 1 :
1) DEFINE DATABASE AND DBMS ? - 3 MARKS
What is Database?
A database is a systematic collection of data. They support electronic
storage and manipulation of data. Databases make data management
easy.
OR
Database handlers create a database in such a way that only one set of
software program provides access of data to all the users.
There are many dynamic websites on the World Wide Web nowadays
which are handled through databases. For example, a model that checks
the availability of rooms in a hotel. It is an example of a dynamic website
that uses a database.
OR
Controls redundancy :It stores all the data in a single database file, so it
can control data redundancy.
Data sharing : An authorized user can share the data among multiple
users.
Disadvantage of DBMS :
Size :It occupies large disk space and large memory to run efficiently.
DBMS gives an abstract view of File system provides the detail of the data
data that hides the details. representation and storage of data.
DBMS provides a crash recovery File system doesn't have a crash mechanism,
mechanism, i.e., DBMS protects i.e., if the system crashes while entering some
the user from the system failure. data, then the content of the file will lost.
DBMS contains a wide variety of File system can't efficiently store and retrieve
sophisticated techniques to the data.
store and retrieve the data.
DBMS takes care of Concurrent In the File system, concurrent access has
access of data using some form many problems like redirecting the file while
of locking. other deleting some information or updating
some information.
#DATABASE MODEL :
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.
*Hierarchical Model
*Network Model
*Entity-relationship Model
*Relational Model
*Object-Oriented Data Model
*Object-Relational Data Model
1) Hierarchical Model :
This database model organises data into a tree-like-structure, with a
single root, to which all the other data is linked. The heirarchy starts
from the Root data, and expands like a tree, adding child nodes to the
parent nodes. In this model, a child node will only have a single parent
node. This model efficiently describes many real-world relationships
like index of a book, recipes etc.
2) Network Model :
This is an extension of the Hierarchical model. In this model data is
organised more like a graph, and are allowed to have more than one
parent node.In this database model data is more related as more
relationships are established in this database model. Also, as the data is
more related, hence accessing the data is also easier and fast. This
database model was used to map many-to-many data relationships.
3) Entity-relationship Model :
In this database model, relationships are created by dividing object of
interest into entity and its characteristics into attributes. E-R Models
are defined to represent the relationships into pictorial form to make it
easier for different stakeholders to understand.
4) Relational Model :
In this model, data is organised in two-dimensional tables and the
relationship is maintained by storing a common field.The basic
structure of data in the relational model is tables. All the information
related to a particular type is stored in rows of that table.Hence, tables
are also known as relations in relational model.
6) Object-Relational Model :
As the name suggests it is a combination of both the relational model
and the object-oriented model. This model was built to fill the gap
between object-oriented model and the relational model.
6) EXPLAIN DATABASE USERS ? - 3 MARKS OR 5 MARKS
#DATABASE USERS
*Naive
*System Analyst
*Sophisticated Users
*Application Program
*Specialized users
1) Naive :
Parametric End Users are the unsophisticated who don’t have
any DBMS knowledge but they frequently use the data base
applications in their daily life to get the desired results.
2) System Analyst :
System Analyst is a user who analyzes the requirements of
parametric end users. They check whether all the requirements
of end users are satisfied.
3) Sophisticated Users :
Sophisticated users can be engineers, scientists, business
analyst, who are familiar with the database. They can develop
their own data base applications according to their
requirement. They don’t write the program code but they
interact the data base by writing SQL queries directly through
the query processor.
4) Application Program :
Application Program are the back end programmers who writes
the code for the application programs.They are the computer
professionals. These programs could be written in
Programming languages such as Visual Basic, Developer, C,
FORTRAN, COBOL etc.
5)Specialized users
Specialized users are sophisticated users who write specialized
database applications that do not fit into the traditional data-
processing framework. Among these applications are
computer-aided design systems, knowledge base and expert
systems, systems that store data with complex data types (for
example, graphics data and audio data), and environment-
modelling systems.
7) EXPLAIN 3 SCHEMA ARCHITECTURE OF DBMS ? - //ESSAY
(N.B)
Three schema Architecture :
o The three schema architecture is also called ANSI/SPARC
architecture or three-level architecture.
o This framework is used to describe the structure of a specific
database system.
o The three schema architecture is also used to separate the
user applications and physical database.
o The three schema architecture contains three-levels. It breaks
the database down into three different categories.
1. Internal Level :
2. Conceptual Level :
3. External Level :
Database Language :
ER model :
o ER model stands for an Entity-Relationship model. It is a high-level
data model. This model is used to define the data elements and
relationship for a specified system.
o It develops a conceptual design for the database. It also develops
a very simple and easy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram
called an entity-relationship diagram.
Component of ER Diagram :
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an
entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee,
department etc. can be taken as an entity.
An entity that depends on another entity called a weak entity. The weak
entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.
We can convert any weak entity set to a strong entity set by simply adding
appropriate attributes
2. Attribute :
The attribute is used to describe the property of an entity. Eclipse is
used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a
student.
a. Key Attribute :
The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented by
an ellipse with the text underlined.
b. Composite Attribute :
c. Multivalued Attribute :
An attribute can have more than one value. These attributes are known
as a multivalued attribute. The double oval is used to represent
multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute :
For example, A person's age changes over time and can be derived from
another attribute like Date of birth.
3 .CONSTARINTS :-
Constraints are used for modeling limitations on the relations between
entities.
There are two types of constraints on the Entity Relationship (ER)
model −
* Mapping cardinality or cardinality ratio.
* Participation constraints.
Mapping Cardinality :-
It is expressed as the number of entities to which another entity can be
associated via a relationship set.
For example, A female can marry to one male, and a male can marry to
one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then
this is known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is
done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one
instance of an entity on the right associates with the relationship then it
is known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have
many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have
many employees.
Total participation :
The participation of an entity set E in a relationship set R is said to be
total if every entity in E Participates in at least one relationship in R.
For Example − Participation of loan in the relationship borrower is total
participation.
Partial Participation :
If only some of the entities in E participate in relationship R, then the
participation of E in R is said to be partial participation.
For example − Participation of customers in the relationship borrower is
partial participation.
2 ) WHAT IS DOMAIN ?
In data management and database analysis, a Data Domain refers to all
the valid values which a data element (column) may contain. The rule for
determining the domain boundary may be as simple as a data type with
a list of possible values.
For example, a database table that has information about people, with
one record per person, might have an "age" column. This gender column
might be declared as a SMALLINT data type, and allowed to have a value
between 0 and 120. The data domain for the age column is hence 0 - 120.
Types of key:
1. Primary key
o It is the first key which is used to identify one and only one
instance of an entity uniquely. An entity can contain multiple keys
as we saw in PERSON table. The key which is most suitable from
those lists become a primary key.
o In the EMPLOYEE table, ID can be primary key since it is unique for
each employee. In the EMPLOYEE table, we can even select
License_Number and Passport_Number as primary key since they
are also unique.
o For each entity, selection of the primary key is based on
requirement and developers.
2. Candidate key
For example: In the EMPLOYEE table, id is best suited for the primary
key. Rest of the attributes like SSN, Passport_Number, and
License_Number, etc. are considered as a candidate key.
3. Super Key
Super key is a set of an attribute which can uniquely identify a tuple.
Super key is a superset of a candidate key.
4. Foreign key
o Foreign keys are the column of the table which is used to point to
the primary key of another table.
o In a company, every employee works in a specific department,
and employee and department are two different entities. So we
can't store the information of the department in the employee
table. That's why we link these two tables through the primary key
of one table.
o We add the primary key of the DEPARTMENT table,
Department_Id as a new attribute in the EMPLOYEE table.
o Now in the EMPLOYEE table, Department_Id is the foreign key,
and both the tables are related.
4 ) EXPLAIN E-R FEATURES ? - GENERALIZATION ,
SPECIALIZATION , AGGREGATION - (N.B) //ESSAY
Generalization :-
Generalization is like a bottom-up approach in which two or more
entities of lower level combine to form a higher level entity if they have
some attributes in common.
In generalization, an entity of a higher level can also combine with the
entities of the lower level to form a further higher level entity.
Generalization is more like subclass and superclass system, but the only
difference is the approach. Generalization uses the bottom-up approach.
In generalization, entities are combined to form a more generalized
entity, i.e., subclasses are combined to make a superclass.
For example, Faculty and Student entities can be generalized and create
a higher level entity Person.
Specialization :
o Specialization is a top-down approach, and it is opposite to
Generalization. In specialization, one higher level entity can be
broken down into two lower level entities.
o Specialization is used to identify the subset of an entity set that
shares some distinguishing characteristics.
o Normally, the superclass is defined first, the subclass and its
related attributes are defined next, and relationship set are then
added.
For example: Center entity offers the Course entity act as a single entity
in the relationship which is in a relationship with another entity visitor.
In the real world, if a visitor visits a coaching center then he will never
enquiry about the Course only or just about the Center instead he will
ask the enquiry about both.
Relational key: In the relational key, each row has one or more
attributes. It can identify the row in the relation uniquely.
Relational Algebra :
1. Select Operation:
Notation: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may use
connectors like: AND OR and NOT. These relational can use as
relational operators like =, ≠, ≥, <, >, ≤.
Input:
σ BRANCH_NAME="perryride" (LOAN)
Output:
Where
Input:
Output:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
3. Union Operation:
Notation: R ∪ S
Example:
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
Input:
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
4. Set Intersection:
Notation: R ∩ S
Input:
Output:
CUSTOMER_NAME
Smith
Jones
5. Set Difference:
Notation: R - S
Input:
Output:
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
6. Cartesian product
Notation: E X D
Example:
EMPLOYEE
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
Input:
EMPLOYEE X DEPARTMENT
Output:
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
7. Rename Operation:
ρ(STUDENT1, STUDENT)
Functional Dependency :
The functional dependency is a relationship that exists between two
attributes. It typically exists between the primary key and non-key
attribute within a table.
X → Y
For example:
Emp_Id → Emp_Name
( 1NF,2NF,3NF,BCNF,4NF,5NF) - //ESSAY
Normalization :
Normal Description
Form
EMPLOYEE table:
14 John 7272826385, UP
9064738238
The decomposition of the EMPLOYEE table into 1NF has been shown
below:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE
14 John 7272826385 UP
14 John 9064738238 UP
Example: Let's assume, a school can store the data of teachers and the
subjects they teach. In a school, a teacher can teach more than one
subject.
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some
candidate key.
Example:
EMPLOYEE_DETAIL table:
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone
are keys.
To convert the given table into BCNF, we decompose it into three tables:
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
Now, this is in BCNF because left side part of both the functional
dependencies is a key.
Example :
STUDENT
21 Computer Dancing
21 Math Singing
34 Chemistry Dancing
74 Biology Cricket
59 Physics Hockey
The given STUDENT table is in 3NF, but the COURSE and HOBBY are two
independent entity. Hence, there is no relationship between COURSE
and HOBBY.
So to make the above table into 4NF, we can decompose it into two
tables:
STUDENT_COURSE
STU_ID COURSE
21 Computer
21 Math
34 Chemistry
74 Biology
59 Physics
STUDENT_HOBBY
STU_ID HOBBY
21 Dancing
21 Singing
34 Dancing
74 Cricket
59 Hockey
Example
So to make the above table into 5NF, we can decompose it into three
relations P1, P2 & P3:
P1
SEMESTER SUBJECT
Semester 1 Computer
Semester 1 Math
Semester 1 Chemistry
Semester 2 Math
P2
SUBJECT LECTURER
Computer Anshika
Computer John
Math John
Math Akash
Chemistry Praveen
P3
SEMSTER LECTURER
Semester 1 Anshika
Semester 1 John
Semester 1 John
Semester 2 Akash
Semester 1 Praveen
Multivalued Dependency :
A B C
12 25 34
10 36 09
12 42 30
A B
12 25
10 36
A B
12 42
R2 (B, C)
B C
25 34
36 09
42 30
A B C
12 25 34
10 36 09
12 42 30
The relation is the same as the original relation R. Hence, the above
decomposition is Lossless-join decomposition.
The following are the most commonly used SQL aggregate functions:
To get the number of products in the products table, you u see the
COUNT function as follows:
SELECT
COUNT(*)
FROM
product
AVG function :
To calculate the average units in stock of the products, you use the
AVG function as follows:
SELECT
AVG(unitsinstock)
FROM
products;
SUM function :
To calculate the sum of units in stock by product category, you use the
SUM function with the GROUP BY clause as the following query:
SELECT
categoryid, SUM(unitsinstock)
FROM
products
GROUP BY categoryid;
MIN function :
SELECT
MIN(unitsinstock)
FROM
products;
MAX function :
SELECT
MAX(unitsinstock)
FROM
products;
SQL Commands :
SQL can perform various tasks like create a table, add data to tables,
drop the table, modify the table, set permission for users.
o CREATE
o ALTER
o DROP
o TRUNCATE
Syntax:
Example:
b. DROP: It is used to delete both the structure and record stored in the
table.
Syntax:
Example
Syntax:
EXAMPLE :
Syntax:
Example:
o INSERT
o UPDATE
o DELETE
Syntax:
Or
For example:
1. INSERT INTO TABLE_NAME (Author, Subject) VALUES ("Sonoo", "D
BMS");
Syntax:
For example:
1. UPDATE students
2. SET User_Name = 'Sonoo'
3. WHERE Student_Id = '3'
Syntax:
For example:
DCL commands are used to grant and take back authority from any
database user.
o Grant
o Revoke
Example
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;
Example
Integrity Constraints :
DDL does not use WHERE clause in its While DML uses WHERE clause
statement. in its statement.
1. GROUP BY :
Syntax
1. SELECT column
2. FROM table_name
3. WHERE conditions
4. GROUP BY column
5. ORDER BY column
Example:
2. HAVING :
Syntax:
Example:
3. ORDER BY
Syntax:
Where:
EXAMPLE :
1. SELECT *
2. FROM CUSTOMER
3. ORDER BY NAME ASC OR DESC;
Triggers :
Triggers are the SQL statements that are automatically
executed when there is any change in the database. The
triggers are executed in response to certain events(INSERT,
UPDATE or DELETE) in a particular table. These triggers help in
maintaining the integrity of the data by changing the data of
the database in a systematic fashion.
Syntax :
Example :
Suppose we have a table named Student containing the
attributes Student_id, Name, Address, and Marks.
Now, we want to create a trigger that will add 100 marks to
each new row of the Marks column whenever a new student is
inserted to the table.
After creating the trigger, we will write the query for inserting a new
student in the database.
Disadvantages of Triggers:
ACID Properties :
1) Atomicity: The term atomicity defines that the data remains atomic.
It means if any operation is performed on the data, either it should be
performed or executed completely or should not be executed at all. It
further means that the operation should not break in between or
execute partially. In the case of executing operations on the
transaction, the operation should be completely executed and not
partially.
2) Consistency: The word consistency means that the value should
remain preserved always. In DBMS, the integrity of the data should be
maintained, which means if a change in the database is made, it should
remain preserved always. In the case of transactions, the integrity of
the data is very essential so that the database remains consistent
before and after the transaction. The data should always be correct
3) Isolation: The term 'isolation' means separation. In DBMS, Isolation
is the property of a database where no data should affect the other
one and may occur concurrently. In short, the operation on one
database should begin when the operation on the first database gets
complete. It means if two operations are being performed on two
different databases, they may not affect the value of one another. In
the case of transactions, when two or more transactions occur
simultaneously, the consistency should remain maintained. Any
changes that occur in any particular transaction will not be seen by
other transactions until the change is not committed in the memory.