Download DBMS PART 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Open Database Connectivity wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
DBMS PART 1
Course code –Mcs 023
Course Name-DBMS
Assignment Valid Upto April 2016
Ans of Qno 3:Consider the following EMP table:
ENAME
DEPT-NAME
DESIGNATION
SALARY
DATE-OF-JOIN
KARAN
FARAH
ACCOUNTING
RESEARCH
DIRECTOR
ANALYST
50000
30000
Nov 17, 2012
Dec 03, 1991
SCINDIA
JOY
RESEARCH
RESEARCH
ANALYST
MANAGER
30000
29750
Dec 09, 2002
Apr 02, 2011
BHASKAR
SALES
MANAGER
28500
May 01, 1999
CHANDER
ACCOUNTING
MANAGER
24500
Jun 09, 2000
ANIL
SALES
SALESMAN
16000
Feb 20, 1991
TOMAR
SALES
SALESMAN
15000
Sep 08, 2001
MILIND
ACCOUNTING
CLERK
13000
Jan 23, 2002
SAXENA
SALES
SALESMAN
12500
Sep 28, 1999
TOMAR
SALES
SALESMAN
14500
Feb 22, 1997
ANAND
RESEARCH
CLERK
11000
Jan 12, 1993
GEORGE
SALES
CLERK
9500
Dec 03, 1990
SURESH
RESEARCH
CLERK
8000
Dec 17, 1992
Answer the following queries in SQL.
(i)
Find all the ENAME‟s whose salary is < Rs.20000
SELECT EMP.EName FROM EMP WHERE ((EMP.SALARY)<20000));
(ii)
Find all the employees working with SALES Department and
with designation MANAGER
SELECT EMP.EName, EMP.DESIGNATION
1
DBMS PART 1
(iii)
(iv)
(v)
(vi)
(vii)
(viii)
(ix)
(x)
FROM EMP
WHERE (((EMP.DEPT_NAME)="SALES") AND
((EMP.DESIGNATION)="MANAGER"));
Find all employees whose name starts with S.
Select * from EMP where ENAME LIKE ‘s%’;
Find total number of employees who work with RESEARCH
department.
SELECT EMP.EName, EMP.DEPT_NAME
FROM EMP
GROUP BY EMP.EName, EMP.DEPT_NAME
HAVING (((EMP.DEPT_NAME)="research"));
Find all the employees who joined after Jan 1, 2010.
SELECT EMP.*, EMP.[DATE-OF-JOIN]
FROM EMP
WHERE (((EMP.[DATE-OF-JOIN])>#1/1/2010#));
Count number of employees whose salary is between Rs.8000 and
Rs.12500.
SELECT EMP.*
FROM EMP
WHERE (((EMP.SALARY) Between 8000 And 12500));
Sort the supplier table by ENAME.
SELECT EMP.*
FROM EMP
ORDER BY EMP.EName;
Find the employees whose designation is SALESMAN and joined
after 1st Aug, 1990.
SELECT EMP.*, EMP.[DATE-OF-JOIN]
FROM EMP
WHERE (((EMP.DESIGNATION)="SALESMAN") AND
((EMP.[DATE-OF-JOIN])>#8/1/1990#));
Find all the employees whose designation is CLERK.
SELECT EMP.*
FROM EMP
WHERE (((EMP.DESIGNATION)="clerk"));
Count number of SALESMAN in SALES department
SELECT EMP.*
FROM EMP
WHERE (((EMP.DESIGNATION)="SALESMAN"));
2
DBMS PART 1
(xi)
Count all the number of employees who are working with the
company.
(xii) Find S# of supplier who supply part „p2‟
(xiii) Find the employees joined between 1st Jan, 1997 and 31st Dec,
2010.
SELECT EMP.*
FROM EMP
WHERE (((EMP.[DATE-OF-JOIN]) Between #1/1/1997# And
#12/31/2010#));
(xiv) Sort the table by the SALARY, descending order.
SELECT EMP.*
FROM EMP
ORDER BY EMP.SALARY DESC;
(xv)
Find the employees with similar names and display their
designation, department and data of join.
4. (a) Discuss the advantages and disadvantages of hierarchical database management system
in comparison with RDBMS. Discuss types of applications suitable for hierarchical DBMS
and RDBMS.
Ans-The Hierarchical model was essentially born from the first mainframe database management system. It
uses an upside-down tree to structure data. The top of the tree is the parent and the branches are children. Each
child can only have one parent but a parent can have many children.
Advantages







Have many different structures and forms.
Structures data in an upside-down tree.
Manages large amounts of data.
Express the relationships between information.
Many children per parent.
Distribute data in terms of relationships.
Improve data sharing.
Disadvantages




One parent per child.
Complex (users require physical representation of database)
Navigation system is complex.
Data must be organized in a hierarchical way without compromising the information.
3
DBMS PART 1



Lack structural independence.
Many too many relationships not supported.
Data independence.
List of Application Where Hierarchical models are Applicable:
1. University
2. Hospital
3. Bank
4. College etc.
Qno 4(b) .Ans-
Integrity Rules
Integrity rules may sound very technical but they are simple and straightforward rules that each table must
follow.
These are very important in database design, when tables break any of the integrity rules our database will
contain errors when retrieving information.
Hence the name "integrity" which describes reliability and consistency of values.
there are two types of integrity rules that we will look at:
Entity Integrity Rule
Referential Integrity Rule
Entity Integrity Rule:
The entity integrity rule refers to rules the primary key must follow.
The primary key value cannot be null.
The primary key value must be unique.
If a table does not meet these two requirements, we say the table is violating the entity integrity rule.
4
DBMS PART 1



The team table violates the entity integrity rules at two places.
Team Super- missing primary key
Super Ultra Mega Team and Best Team in the World -has the same primary key.
Referential Integrity Rule:






The referential integrity rule refers to the foreign key.
The foreign key may be null and may have the same value but:
The foreign key value must match a record in the table it is referring to.
Tables that do not follow this are violating the referential integrity rule.
The Player table violates the referential integrity rule at these places:
Player P8 and P9 - these players are in teamID T8, which does not exist in the Team Table.
Qno 5 (A) Ans- Database design is connected with application design.
The requirements and the collection analysis phase produce both data requirements and functional
5
DBMS PART 1
requirements. The data requirements are used as a source of database design. The data requirements
should be specified in as detailed and complete form as possible.
In parallel with specifying the data requirements, it is useful to specify the known functional
requirements of the application. These consist of user-defined operations that will be applied to the
database (retrievals and updates). The functional requirements are used as a source of application
software design. Of course some functions may produce also needs for database design.
Note that some phases are database management system independent and some are dependent. The
idea is to design first the database without thinking about the actual database system - just to
concentrate on the data.
Conceptual Design
Once all the requirements have been collected and analyzed, the next step is to create a conceptual
shema for the database, using a high level conceptual data model. This phase is called conceptual
design.
The result of this phase is an Entity-Relationship (ER) diagram or UML class diagram. It is a high-level
data model of the specific application area. It describes how different entities (objects, items) are
related to each other. It also describes what attributes (features) each entity has. It includes the
definitions of all the concepts (entities, attributes) of the application area.
During or after the conceptual shema design, the basic data model operations can be used to specify
the high-level user operations identified during the functional analysis. This also serves to confirm that
6
DBMS PART 1
the conceptual schema meets all the indenfied functional requirements.
There are several notations to draw the ER diagram.
Logical Design
The result of the logical design phase (or data model mapping phase) is a set of relation shcemas. The
ER diagram or class diagram is the basis for these relation schemas.
To create the relation shemas is quite a mechanical operation. There are rules how the ER model or
class diagram is transferred to relation shemas.
The relation schemas are the basis for table definitions. In this phase (if not done in previous phase)
the primary keys and foreign keys are defined.
Physical Design
The goal of the last phase of database design, physical design, is to implement the database. At this
phase one must know which database management system (DBMS) is used. For example, different
DBMS's have different names for datatypes and have different datatypes.
The SQL clauses to create the database are written. The idexes, the integrity constraints (rules) and
the users' access rights are defined.
Finally the data to test the database is added in.
In parallel with these activities, application programs are designed. The implementation of the
programs can start when the database is created and data has been added in.
Qno 5 (b) Ans-
Data Independence
A database system normally contains a lot of data in addition to users’ data. For example,
it stores data about data, known as metadata, to locate and retrieve data easily. It is
rather difficult to modify or update a set of metadata once it is stored in the database. But
as a DBMS expands, it needs to change over time to satisfy the requirements of the users.
If the entire data is dependent, it would become a tedious and highly complex job.
7
DBMS PART 1
Metadata itself follows a layered architecture, so that when we change data at one layer,
it does not affect the data at another level. This data is independent but mapped to each
other.
Logical Data Independence
Logical data is data about database, that is, it stores information about how data is
managed inside. For example, a table (relation) stored in the database and all its
constraints, applied on that relation.
Logical data independence is a kind of mechanism, which liberalizes itself from actual data
stored on the disk. If we do some changes on table format, it should not change the data
residing on the disk.
Physical Data Independence
All the schemas are logical, and the actual data is stored in bit format on the disk. Physical
data independence is the power to change the physical data without impacting the schema
or logical data.
For example, in case we want to change or upgrade the storage system itself − suppose
we want to replace hard-disks with SSD − it should not have any impact on the logical
data or schemas.
8