P. 1
Rdbms Vpl Lab Manual

Rdbms Vpl Lab Manual

|Views: 903|Likes:
Published by Amit Sangale

More info:

Published by: Amit Sangale on Jan 31, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC or read online from Scribd
See more
See less

07/06/2013

Title of Assignment : Design and draw an ER/EER diagram using standard notations
for given problem definition and convert this diagram into Database Tables.

Relevant Theory / Literature Survey: (Brief Theory Expected)
.Data Model

Data Model is collection of conceptual tools for describing

•data
•data relationship
•data semantics and
•consistency constraints
Data Model are classified into three types
1.Object Based logical model
(a)ER Model
(b)Object oriented model
(c)Function Model

2.Recored-Based logical Model

(a)Relationship Model
(b)Network Model
(c)Hierarchical Model

3.Physical Model

(a)Unifying Model
(b)Frame Memory

Entity-Relationship Diagram:-

An E-R diagram can express the overall logical structure of a database graphically. E-
R diagrams are simple and clear-qualities that may well account in large part for the
Widespread use of the E-R Model. Such a diagram consist of the following major
component.
Rectangles:- which represents entity set
Ellipses:-which represent attribute
Diamonds:-which represent relationship sets
Lines:-Which link attributes to entity sets and entity set to relationship sets.
Double Ellipses:- which denote derived attributes
Double Lines:- which indicates total participation of entity in a relationship set
Double Rectangles:- which represents weak entity sets.

Extended ER Features:-

Following are the Extended Entity Relationship Features of E-R Model
1.Specialization
2.Generalization
3.Aggretion
4.Attributes Inheritance

Specialization:-

It is the process of designing sub groupings within an entity set. Consider an account
entity which can be classified into
•Saving Account
•Checking’s Account
Checking account can be further be classified into
•Standard
•Gold
•Senior

6

RDBMS & VB MANUAL

Hence, Specialization of account entity is savings account and checking account
Specialization of checking account is standard, gold and senior checking account. In
E-R diagram, Specialization is depicted by a triangle component labeled ISA.

Generalization:-

It is a containment relationship that exists between a higher level entity set and one
more lower level entity set .Attributes of higher level entity set and of lower level entity
set are common. this commonality is express by generalization

Aggregation:-

Aggregation is an abstraction through which relationship are treated as higher-level
entities.It helps to express relationship among relationships. To illustrate the need of
aggregation consider the database describing information about employees who work
on particular project and use a number of different machines in their work.

Attributes Inheritance:

A crucial property of the higher and lower level entity created by specialization and
generalization is “attribute inheritance” .The attributes of higher of higher-level entity
set are said to be inherited by the lower-level entity set .A lower level entity sets(or
subclass) also inherits participation in the relationship sets in which its higher-level
entity(or super class) participates.

Design Analysis / Implementation Logic:
(Algorithm / Flow Chart / Pseudo Code / UML diagram / DFD as per requirement)
Steps in E-R Modeling

•Identify the entities
•Find relationships
•Identify key attributes for every entity
•Identify other relevant attributes
•Draw complete E-R diagram with all attributes including Primary key.

Testing:

(Input/ Output)

Case Study – ER Model For a college DB

Assumptions :

• A college contains many departments
• Each department can offer any number of courses
• Many instructors can work in a department
• An instructor can work only in one department
• For each department there is a Head
• An instructor can be head of only one department
• Each instructor can take any number of courses
• A course can be taken by only one instructor
• A student can enroll for any number of courses
• Each course can have any number of students

Step 1: Identify the Entities

• DEPARTMENT
• STUDENT
• COURSE
• INSTRUCTOR

Step 2: Find the relationships

• One course is enrolled by multiple students and one student enrolls for multiple
7

RDBMS & VB MANUAL

courses,hence the cardinality between course and student is Many to Many.
• The department offers many courses and each course belongs to only one department,
hence the cardinality between department and course is One to Many.
• One department has multiple instructors and one instructor belongs to one and only
one department , hence the cardinality between department and instructor is one to
Many.
• Each department there is a “Head of department” and one instructor is “Head of
department “,hence the cardinality is one to one .
• One course is taught by only one instructor, but the instructor teaches many
courses,hence the cardinality between course and instructor is many to one.

Step 3: Identify the key attributes

• Deptname is the key attribute for the Entity “Department”, as it identifies the
Department uniquely.
• Course# (CourseId) is the key attribute for “Course” Entity.
• Student# (Student Number) is the key attribute for “Student” Entity.
• Instructor Name is the key attribute for “Instructor” Entity.

Step 4: Identify other relevant attributes

• For the department entity, the relevant attribute is location
• For course entity, course name,duration,prerequisite
• For instructor entity, room#, telephone#
• For student entity, student name, date of birth

Step 5: Draw complete E-R diagram with all attributes including Primary Key

Conclusion:

Thus we have studied and implemented the ER-Model for college DB.

Assignment No. 3

8

RDBMS & VB MANUAL

Title of Assignment :

Create tables with ORACLE using SQL DDL statements. Use SQL DML statement
such as INSERT, UPDATE and DELETE to insert the data into tables and to
update/delete the data inserted into/from tables. Write and execute SQL queries to
extract information from the table.

Relevant Theory / Literature Survey: (Brief Theory Expected)
SQL

• SQL is used to make a request to retrieve data from a Database.
• The DBMS processes the SQL request, retrieves the requested data from theDatabase,
and returns it.
• This process of requesting data from a Database and receiving back the
results is called a Database Query and hence the name Structured Query language
• SQL is a language that all commercial RDBMS implementations understand.
• SQL is a non-procedural language
• We would be discussing SQL with respect to oracle syntax
Components of SQL-

SQL is Comprised of three sub languages. They are data definition(DDL). Data
Manipulation (DML) and data control language(DCL).

1.Data Definition Language(DDL)

It consist of set of commands used to create the database objects such as tables, view
and indexes .This include commands like create, alter and draw.

2.Data Manipulation Language(DML)

It is used for query, insertion , updation and deletion of data stored in database .This
include commands like select insert and update.

3.Data Control Language(DCL)

It is used for controlling access to the data. This include commands like select Grant
Rollback, Commit and Revoke.

Limitation Of SQL

It is not possible to include the declaration and also not possible to use variables and
constants which are supporting constructs to control the flow of execution.

Design Analysis / Implementation Logic:
(Algorithm / Flow Chart / Pseudo Code / UML diagram / DFD as per requirement)
Queries to be Implemented :-
1 CREATE
- to create objects in the database
Syntax:

Create table

((), type>());
The different constraints can be used while creating the table.
1.NULL Constraint
It Specifies that a column contain NULL Variable.
2.NOT NULL Constraint
It specifies that a column cannot contain a NULL value.
3.PRIMARY KEY

It designates a column or combination of columns as a primary key. It satisfies NOT
NULL and UNIQUE constraint implicitly.
4.REFERENCES

Identifies the Primary Key i.e. referenced by a foreign key in referential integrity
constraint.
5.FOREIGN KEY

It designates a column or combination of columns as foreign key in referential
integrity constraint.

6.CHECK

It specifies a condition that each row in a table must satisfy.
9

RDBMS & VB MANUAL

2 ALTER - alters the structure of the database
Syntax:

ALTER TABLE tablename (ADD/MODIFY/DROP column_name);
3 DROP - delete objects from the database
Syntax:
DROP TABLE <
TableName>;
4 TRUNCATE - remove all records from a table, including all spaces allocated for the
records are removed.

Syntax:
TRUNCATE TABLE <
TableName>;
5 INSERT - insert data into a table
Syntax:

INSERT INTO tablename (Columnlist) VALUES (value list);
6 SELECT
- retrieve data from the a database
Syntax:

Select, from

;
Select * from
;
Select * from
where ;
7 UPDATE - updates existing data within a table
Syntax:
UPDATE
tablename SET column_name =value [ WHERE condition]
8 DELETE - deletes all records from a table, the space for the records remain
Syntax:
DELETE
FROM tablename WHERE condition
SQL - Aggregate functions :-

• Used when information you want to extract from a table has to do with the
data in the entire table taken as a set.
• Aggregate functions are used in place of column names in the SELECT
statement
• The aggregate functions in sql are :

SUM( ) , AVG( ) , MAX( ) , MIN( ), COUNT( )

SUM ( [ DISTINCT ] Column-name / Expression )
AVG ( [ DISTINCT ] Column-name / Expression )
MIN ( Expression )
MAX ( Expression )
COUNT ( [ DISTINCT ] Column-name )
Count( * )

Testing: (Input/ Output)
CREATE TABLE Customer_Details(
Cust_ID Number(5) CONSTRAINT Nnull1 NOT NULL,
Cust_Last_Name VarChar2(20) CONSTRAINT Nnull2 NOT NULL,
Cust_Mid_Name VarChar2(4),
Cust_First_Name VarChar2(20),
Account_No Number(5) CONSTRAINT Pkey1 PRIMARY KEY,
Account_Type VarChar2(10) CONSTRAINT Nnull3 NOT NULL,
Bank_Branch VarChar2(25) CONSTRAINT Nnull4 NOT NULL,
Cust_Email VarChar2(30)
);

ALTER TABLE Customer_Details
ADD Contact_Phone Char(10);

10

RDBMS & VB MANUAL

ALTER TABLE Customer_Details
MODIFY Contact_Phone Char(12);

ALTER TABLE Customer_Details
DROP (Contact_Phone);

DROP TABLE UnqTable;

TRUNCATE TABLE Customer_Details;

INSERT INTO Customer_Details
VALUES (106, 'Costner', 'A.', 'Kevin', 3350, 'Savings', 'Indus Bank',
'Costner_Kevin@times.com');

SELECT * FROM Customer_Details;
SELECT Cust_First_Name FROM Customer_Details;

SELECT Cust_ID, Account_No FROM Customer_Details

WHERE Cust_First_Name = ‘Graham’;

UPDATE Customer_Fixed_Deposit
SET Cust_Email = ‘Quails_Jack@rediffmail.com’ ,Rate_of_Interest_in_Percent = 7.3
WHERE Cust_ID = 104 ;

DELETE FROM Customer_Details;

DELETE FROM Customer_Details WHERE Cust_ID = 102;

SELECT MIN (Total_Available_Balance_in_Dollars) FROM Customer_Transaction;

SELECT MAX (Total_Available_Balance_in_Dollars) FROM Customer_Transaction;

SELECT AVG (Total_Available_Balance_in_Dollars) FROM Customer_Transaction;

SELECT MIN (Total_Available_Balance_in_Dollars),
SUM (Total_Available_Balance_in_Dollars) FROM Customer_Transaction;

SELECT COUNT (*) FROM Employee_Manager;

SELECT COUNT (Manager_ID) FROM Employee_Manager;
Conclusion: Thus we have studied and understood SQL .

11

RDBMS & VB MANUAL

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->