Important Question For DBMS
Important Question For DBMS
Page 1
1. Explain advantages of DBMS.
Ans:
1. Minimal Data Redundancy: Due to centralized database, it is possible to avoid
unnecessary duplication of information. Ex. All information about bank customer
can be kept centralized.
2. Improved Data Inconsistency: Data inconsistency occurs due to data redundancy.
Due to centralized database it is possible to avoid unnecessary duplication of
information.
3. Efficient Data Access: DBMS provides a variety of techniques to retrieve data.
4. Improved Data Sharing: In DBMS Data is maintained centrally, all authorized users
and application programs can share this data easily.
5. Improved Data Integrity: Data integrity means that data contained in the database
is both correct and consistent. DBMS software provides different way to implement
such types of rules.
6. Guaranteed Atomicity: Any operation on database must be atomic. It is
responsibility of the DBMS software ensure such kind of atomicity.
7. Improved Concurrent Access: Multiple users are allowed to access data
simultaneously (concurrently). As Database is maintained centrally, data can be
shared easily among multiple users.
8. Improved Security: DBMS software provides way to control the access to data for
different user according to their requirements.
Page 2
7. Backup and Recovery: Database is a valuable asset for any organization. It should
not be lost or damaged. The DBA ensures this by taking proper backup of Database.
3. Entity set: A collection of entities of same type are called entity set.
4. Relationships: The association or the ways that different entities relate to each other
is called relationships.
EMPLOYEE EMP_NO
EMPLOYEE SALARY
5. Key: The data item for which a computer uses to identify a record in a database
system is referred to as key. There are several keys available in a table. Two main
keys are primary key and foreign key.
Page 3
4. Explain Data Types of DBMS.
Ans:
There are basic four data types available in SQL.
1) Numerical
2) Character
3) Date
4) Binary
Numerical Data Types
Page 4
DATE Data Types
Page 5
A. Record Based Data Models
The most widely used Record Based Data Models are
Hierarchical Data Model
Network Data Model
Relational Data Model.
1) Hierarchical Data Model
In Hierarchical data model tree concept is used to represent data and relationship
among this data.
The nodes of tree are connected with pointer or link.
In tree structure each child records can have only one parent record, and each parent
record have zero or more than one child so one-to-one or one-to-many relationship is
possible.
The records are represented by rectangular box and relationship between these records
is represented by arcs (pointer).
This type of structure is also known as tree structure diagram.
Page 6
Network Database Model is same like Hierarchical Model, but the only difference is that
it allows a record to have more than one parent.
It replaces the hierarchical tree with a graph.
It represents the data as record types and many-to-many relationship.
This model is easy to design and understand.
This was the most widely used database model, before Relational Model was introduced.
Page 7
7. Explain Group by having and order by with Example.
Ans:
The SQL GROUP BY Clause is used along with the group functions to retrieve data
grouped according to one or more columns.
Syntax:
Select column1, column2……. columnN, Aggregate Function (argument) From
TableName Group By column1, column2……. columnN;
Example:
Dept Salary
Electrical 25000
Electronics 55000
Aeronautics 35000
InfoTech 30000
1) SQL ORDER BY
The ORDER BY keyword is used to sort the result-set in ascending or descending
order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
Syntax:
SELECT column1, column2…..FROM table_name
ORDER BY column1, column2 ... ASC|DESC;
Page 8
100 Ramesh Electrical 24 25000 Bangalore
Example:
Name Salary
Soumya 20000
Ramesh 25000
Priya 30000
Hrithik 35000
Page 9
104 Priya InfoTech 25 30000 Mangalore
SELECT dept, SUM (salary) FROM employee GROUP BY dept HAVING SUM (salary)
> 25000;
Dept salary
Electronics 55000
Aeronautics 35000
InfoTech 30000
1) CREATE
Create command used to create a table in database.
Syntax:
2) ALTER
Used to modify structures of a table.
Used to either add ,modify, or drop columns in a table
Syntax:
Adding New Columns
Page 10
Alter table TableName Add (NewColumnName Datatype (size), NewColumnName
Datatype (size)….);
Modifying Existing Columns
Alter table TableName Modify (ColumnName NewDatatype (NewSize));
Dropping (deleting) Existing Columns
Alter table TableName Drop column ColumnName;
Example:
1) Alter table student ADD (Gender varchar2 (10));
2) Alter table student modify (sname varchar2 (15));
3) alter table student drop column dept;
3) TRUNCATE TABLE
TRUNCATE TABLE used to delete all data from a table
Logically, this is same to DELETE statement that deletes all rows
TRUNCATE command is faster than DELETE command
The number of deleted rows are not returned
Syntax:
TRUNCATE TABLE TableName;
Example:
TRUNCATE TABLE client_master;
4) DROP TABLE
DROP command is used to delete or destroy table from a database
Syntax:
DROP TABLE TableName;
Example:
DROP TABLE client_master;
5) RENAME TABLE
RENAME command is used to rename the existing table Name.
Syntax:
Rename TableName to NewTableName;
Example:
Rename Student to StudentMaster;
DML Commands - (Data-Manipulation language)
DML commands are generally used for manipulating data stored in tables.
So DML commands are work on data stored in tables rather than table definition.
It include following commands
Page 11
1. INSERT
2. UPDATE
3. DELETE
1) INSERT
Used to insert data into a table or create a new row in table.
Syntax:
Insert into TableName (columnname1, columnname2) values (value1, value2);
Example:
Insert into client_master (clientno, name) values (‘C01’,’Preeti’);
2) UPDATE
The UPDATE command is used to change or modify data of a table
Update command used to update Selected rows from table or All the rows from
table
Syntax:
Update TableName Set columnname1 = value1, Columnname2= value2 where
Condition;
Example:
Update client_master Set city=’Bombay’ where clientno=’C01’;
3) DELETE
Delete command used to delete data or rows from a table
delete command used to delete Selected rows from table or All the rows from table
Syntax:
Delete from TableName Where Condition;
Example:
Delete from client_master Where client_no=’C01’;
Page 12
EXTERNAL SCHEMA
EXTERNAL
USER VIEW 1 USER VIEW 2 USER VIEW N
LEVEL
(Application
Program)
(Defined by DBA)
INTERNAL SCHEMA
INTERNAL LEVEL
(Defined by DBA)
PHYSICAL LEVEL
PHYSICAL DATABASE
Page 13
10. Draw and Explain E-R model Symbol.
Ans:
Page 14
Generalization
"Generalization is the process of defining a super-class from sub-classes based
on some common characteristics."
Generalization identifies a super-class from different entity sets.
Some attributes are common to given entity sets.
Generalization is a bottom-up process to define super-class/sub-class
relationships.
Example: consider the two entity sets Car and Truck
Page 15
They have many attributes in common.
Example: vehicle_id, licence_plat_no, company, model, and price are common
attributes to both of these entity sets
Vehicle can be defined as a super-class for two sub-classes Car and Truck.
12. Give the Difference between primary key and unique key.
Ans:
Primary Key Unique Key
A Column defines as primary key does A Column defines as unique key cannot have
not contain duplicate value as well as duplicate value but it have null value.
null value.
Page 16
Syntax: Syntax:
ColumnName Datatype (Size) Primary ColumnName Datatype (Size) Unique Key.
Key.
Example: Create table Account(Ano Example: Create table Account(Ano
number(3) Primary Key, Balance number(3) Unique Key, Balance number(8),
number(8), Branch varchar2(20)); Branch varchar2(20));
Primary Key does not allow null value in Unique Key allows null value as well as
column. duplicate null value in a column.
A table cannot have more than one A Table can have more than one column
primary key. define as unique key.
Page 17
4. Outer Join
INNER JOIN
The inner join is the most common used join in all joins.
The inner join combines only that record which contains common value in both
relations.
Inner join is totally reverse from cross join and it provides consistent record as an
output.
Syntax: select column1,column2,…,colmunN from table1,table2 where
table1.column1 op table2.column1;
In inner join, if both the columns are compared for equality (=op) then it is referred
as ‘Equi join’.
If both the columns are compared for non-equality then join operation is referred as
non-equi join.
Example:
Relation: Student
ID NAME DEPT
1 Anisha CE
2 Tanisha EE
Relation: Hostel
NAME HOSTELNAME ROOMNO
Kanisha ABC 14
Anisha XYZ 12
Tanisha PQR 13
Example:
Select id, Student.Name, dept, RoomNo, HostelName form Student,Hostel where Student
.Name=Hostel.Name;
Output:
Page 18
OUTER JOIN:
Syntax:
SELECT column_name [, column_name] FROM table1 [, table2] WHERE column_name
OPERATOR (SELECT column_name [, column_name] FROM table1 [, table2] [WHERE])
Example:
Id Name Dept Age Salary Location
100 Ramesh Electrical 24 2500 Bangalore
101 Hrithik Electronics 28 6500 Bangalore
102 Harsha Aeronautics 28 5500 Mysore
103 Soumya Electronics 22 2000 Bangalore
104 Priya InfoTech 25 3000 Mangalore
Example:
SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS WHERE
SALARY > 4500);
Output:
Id Name Dept Age Salary Location
101 Hrithik Electronics 28 6500 Bangalore
102 Harsha Aeronautics 28 5500 Mysore
Page 19
16. List set operators and Explain all with Example.
Ans:
There are four types of Set operators.
1) Union
2) Union all
3) Intersect
4) Minus
1) UNION Clause
The UNION clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain all the records from query1 and query2 according to
following.
The number of columns, name of each column and their data types in both relations
must be same.
Syntax: SELECT * FROM table1 UNION SELECT * FROM table2;
Example: SELECT * FROM Emp UNION SELECT * FROM Cust;
Relation: Cust
Relation: Emp ID Name
ID Name 1 Manisha
1 Manisha 2 Tanisha
2 Tanisha 4 Disha
3 Kavisha
Output:
ID Name
1 Manisha
2 Tanisha
3 Kavisha
4 Disha
Page 20
2) UNION ALL Clause
The UNION ALL clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain all the records from query1 and query2 according to
following.
The number of columns, name of each column and their data types in both relations
must be same.
Syntax: SELECT * FROM table1 UNION ALL SELECT * FROM table2;
Example: SELECT * FROM EMP UNION ALL SELECT * FROM Cust;
Relation: EMP Relation: Cust
ID Name ID Name
1 Manisha 1 Manisha
2 Tanisha 2 Tanisha
3 Kavisha 4 Disha
Output:
ID Name
1 Manisha
2 Tanisha
3 Kavisha
1 Manisha
2 Tanisha
4 Disha
3) INTERSECT Clause
The Intersect clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain those records which are common to query1 and query2
according to following.
Page 21
The number of columns, name of each column and their data types in both relations
must be same.
Output: A single set of Records which is common in both queries.
Syntax:
SELECT * FROM table1 INTERSECT SELECT * FROM table2;
Example: SELECT * FROM Emp INTERSECT SELECT * FROM Cust;
Relation: Emp Relation: Cust
ID Name ID Name
1 Manisha 1 Manisha
2 Tanisha 2 Tanisha
3 Kavisha 4 Disha
Output:
ID Name
1 Manisha
2 Tanisha
4) MINUS Clause
The MINUS clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain those records which are present in query1 but not present
in query2 according to following.
The number of columns, name of each column and their data types in both relations
must be same.
Output:
ID Name
3 Kavisha
Page 23
4) Alternate Key
"An alternate key is a candidate key that is not chosen by the database
designer".
Candidate key which are not selected as a primary key are known as
alternate key or secondary key.
Example: in above relation table Sid and phone is candidate key.
Sid is a primary key so phone is an alternate key.
5) Foreign Key
"A foreign key is a set of one or more attributes whose values are derived
from the key attribute of another relation."
This key is used to join two more tables.
Example: Account: ano, balance, bname
Branch: bname, baddress
Here, bname is foreign key for Account table and primary key for Branch
table.
Page 24
5) COUNT()
It returns the number of rows in specified column or the total number
of rows in the table.
Syntax: COUNT (column name)
Example: select COUNT (salesman_no) from salesman_master;
Output: 15
Syntax: COUNT (*)
Example: select COUNT (*) from salesman_master;
Output: 50
Page 25
SQL>select * from employee where city = 'Rajkot' OR city = 'Surat';
ENAME SALARY CITY
------------------- ---------------------- ----------------------
Parimal 15000 Rajkot
Khanjan 12000 Surat
3) The NOT Operator
The NOT operator is used to negate the result of any condition or group of
conditions.
Example:
SQL>select * from employee where not (city = 'Ahmedabad');
ENAME SALARY CITY
------------------- ---------------------- ----------------------
Preet 20000 Jamnagar
Parimal 15000 Rajkot
Khanjan 12000 Surat
20. List types of DBMS and Explain distributed and Centralized DBMS.
Ans:
DBMS can also be classified according to number of users, database site locations,
expected type and extent of use.
(a) On the basis of no of users:
1. Single user system
2. Multi user system
(b) On the basis of site location:
1. Centralized DBMS
2. Parallel DBMS
3. Distributed DBMS
4. Client/Server DBMS
(c) On the basis of type and extent of use:
1. Transactional or Production DBMS
2. Decision Support DBMS
3. Data Warehouse
DISTRIBUTED DATABASE SYSTEM:
Page 26
In distributed database system, one application can operate at different location.
Each machine can have data and application of its own.
Each machine will act as a server for some users and a client for others.
Advantages:
Provide greater efficiency and better performance.
Response time and Throughput is high.
A single database (on server) can be shared across several distinct client
(application) systems.
Disadvantages:
Recovery from failure is more complex.
CENTRALISED DATABASE SYSTEM:
It consists of a single database server and multiple users connected to the server.
It is physically located at single place.
Multiple users can access this database from local machines or from remote
machine.
Management of system and its data are controlled centrally.
Page 27
It provides security in terms of authorization.
Example: small enterprise (Personal Computer) , large enterprise (Mainframe)
Disadvantages:
When central site goes down then everyone (user) is blocked until system comes
back.
Communication costs from terminals to central site can be expensive.
Page 28
Insert, delete or update operation make changes on database.
Example: value of the variable (Column Name) like 1 Rollno of student.
Sub-Schema:
Definition: A subschema is a subset of the schema and inherits the same property
that a schema has.
Subschema refers to an application programmer's (user's) view of the data item
types and record types, which he or she uses.
Page 29
2. Logical data independence
Logical data independence is the ability to modify the logical (conceptual)
schema without requiring any change in applications programs.
Logical data independence separates external level from the conceptual level.
It is difficult to achieve logical data independence.
Page 30
d) Data Warehouse:
Data warehouse is a decision support database that is maintained
separately from the organization’s operational database.
e) Entity:
It is real physical object or event.
Eg: student of college.
f) Attribute:
It is the property of an entity.
Eg: roll no, name branch etc of student.
g) Metadata:
Metadata means data about data.
It is also known as system catalog which is self describe database.
σ (city=’Surat’) <Customer>
Output:
cid cname city
Page 31
102 Neha Surat
103 Preeti Surat
b) Projection
Operation:
Output:
cid cname
101 Shweta
102 Neha
103 Preeti
104 Ami
c) Intersection
Operation:
Selects tuples those are in both relations.
Symbol: ∩ (Intersection)
Notation: Relation 1 ∩ Relation2
Requirement:
Intersection mast ne taken between compatible relations.
Relations R and S are Compatible if
Both have same arity.
Attribute Domain must be compatible.
Example-6: (name) (Employee) ∩ (name) (Customer)
Page 32
d) Cartesian product
Operation:
Combines information of two relations.
It is also known as Cross-product operation and similar
to mathematical Cartesian-product operation.
Symbol: X (cross)
Notation: Relation 1 X Relation2
Resultant Relation:
If Relation1 and Relation2 have n1 and n2 attributes
respectively then, Resultant relation = n1 + n2
attributes
If both relations having same name of attribute, it can
be distinguished by combing 'Relation-name .Attribute-
name'.
If Relation1 and Relation2 have n1 and n2 tuples
respectively, then Resultant relation will have n1 * n2
attributes.
Example: Combine only consistent information from
EMP and Dept relation.
Page 33
e) Rename
Operation:
Rename Relation B to A.
Example: ρ vpmp_student (Student)
Page 34