Beruflich Dokumente
Kultur Dokumente
Name_______________________________________
Class _________
Semester _____
Final Grade:_______
LAB MANUAL
DATABASE TECHNOLOGIES
TE IT Sem VI
Year: 2015- 2016
Course Outcomes:
Upon completion of this course the students will be able to :
2
Experiment no: - 1
TITLE:
3
Write the problem definition of any organization and draw the EER diagram for that
Problem Statement:
EER Diagram:
Remark:
Grade:
Experiment no: - 2
5
TITLE:
Performing practical by using Basic SQL Statements & joining tables.
RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql
PRIOR CONCEPTS:
Database, concept of Database Management System.
NEW CONCEPTS:
Proposition 1: Basic SELECT Statements:
SELECT Retrieves data from the database.
Syntax:SELECT *| {[DISTINCT] column | expression [alias] }
FROM
table;
-
Group Functions: It operate on sets of rows to give one result per group.
Syntax: SELECT [column,] group_function (column),
FROM table
[WHERE condition]
[GROUP BY column]
[ORDER BY column];
- Types of Group Functions:
AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE , COUNT,
e.g.: SELECT AVG (salary), MAX (salary), MIN (salary), and SUM (salary),
COUNT (DISTINCT department_id)
FROM employees;
Conclusion:
This practical covers topics:
- how to write & execute SELECT statements.
- Selecting, restricting, and sorting data.
how to use joins to display data from multiple tables and group functions.
QUESTIONS:
8
2. Find the course id and grades of all courses taken by any student named 'Tanaka'
3. Find the ID and name of instructors who have taught a course in the Comp. Sci.
department, even if they are themselves not from the Comp. Sci. department. To
test this query, make sure you add appropriate data, and include the corresponding
insert statements along with your query.
4. Find the courses which are offered in both 'Fall' and 'Spring' semester (not
necessarily in the same year).
5. Find the names of all the instructors from Comp. Sci. department
9
6. Find the course id and titles of all courses taught by an instructor named
'Srinivasan'
7. Find names of instructors who have taught at least one course in Spring 2009
Remark:
Grade:
Experiment no: - 3
10
TITLE:
Performing practical by using DDL, DML, DCL, Transaction, constraints, and set
operators concepts.
RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql
PRIOR CONCEPTS:
Basic SQL Statements.
NEW CONCEPTS:
Proposition 1: DDL & DML Operations:
CREATE TABLE Statement: create table
e.g.: CREATE TABLE dept
(deptno NUMBER (2),
dname VARCHAR2 (14),
loc VARCHAR2 (13));
ALTER TABLE Statement:
- use to add, modify, define values and drop a column.
Syntax:
1) ALTER TABLE table
ADD
(column datatype [DEFAULT expr]
[, column datatype] );
2) ALTER TABLE table
MODIFY (column datatype [DEFAULT expr]
[, column datatype] );
3) ALTER TABLE table
DROP
(column datatype [DEFAULT expr]
[, column datatype] );
e.g.: 1) Add a column:
ALTER TABLE dept80
ADD (job_id VARCHAR2 (9));
2) Drop a column:
ALTER TABLE dept80
MODIFY (last_name VARCHAR2 (30));
3) Drop a column:
ALTER TABLE dept80
DROP COLUMN job_id;
INSERT Statement: add new rows to a table
e.g.: INSERT INTO departments (department_id, department_name,
11
manager_id, location-id)
VALUES (70, Public Relations, 100, 1700);
UPDATE Statement: modify existing rows.
e.g.: UPDATE employees
SET department_id = 70
WHERE employee_id = 113;
DELETE Statement: remove existing rows from a table
e.g.: DELETE FROM departments
WHERE department_name = Finance;
Proposition 2: DATABASE TRANSACTIONS:
Committing Data:
- make the changes
e.g.: DELETE FROM employees
WHERE employee_id = 99999;
INSERT INTO departments
VALUES (290, Corporate Tax, NULL, 1700);
- Commit the changes
e.g.: COMMIT;
Commit complete.
Sate of data after ROLLBACK
- Discard all pending changes by using the ROLLBACK statement.
e.g.: DELETE FROM copy_emp;
22 rows deleted
ROLLBACK;
Rollback complete.
Proposition 3: CONSTRAINTS:
Defining Constraints:
Syntax: CREATE TABLE [schema.] table
(column datatype [DEFAULT expr]
[ column_constraint],
[table_constraint] [, ] );
Types of Constraint
1. NOT NULL: defining at the column level
2. UNIQUE Constraint: defined at either the table level or the column level.
3. PRIMARY Constraint: defined at either the table level or the column level
4. FOREIGN KEY Constraint: defined at either the table level or the column level
5. CHECK Constraint: define a condition that each row must be satisfy.
e.g.:
CREATE TABLE employees (
employee_id NUMBER (6),
12
Removing View:
Syntax: DROP VIEW view;
e.g.: DROP VIEW empvu80
Proposition 5: CONTROLLING USER ACCESS/ DCL STATEMENTS;
Creating Users:
Syntax: CREATE USER user
IDENTIFIED BY password;
e.g.: CREATE USER scott
IDENTIFIED BY tiger;
User System Privileges:
-Grant specific privileges to the user by administrator.
Syntax: GRANT privilege [, privilege...]
TO user [, user| role, PUBLIC...];
e.g.: GRANT create session, create table, create sequence, create view
TO
scott;
13
Changing Password:
e.g.: ALTER USER scott
IDENTIFIED BY lion;
Object Privileges: Its vary from object to object.
Syntax: GRANT object_priv [(columns)]
ON object
TO {user | role | PUBLIC}
[WITH GRANT OPTION];
e.g.: GRANT select
ON employees
TO sue, rich;
How to Revoke Object Privileges
Syntax: REVOKE {privilege [, privilege...]|ALL}
ON object
FROM {user [, user...]| role| PUBLIC}
[CASCADE CONSTRAINTS];
Database Links:
-Create database link:
e.g.: CREATE PUBLIC DATABASE LINK hq.acme.com
USING 'sales';
- use the database link:
e.g.: SELECT *
FROM emp@HQ.ACME.COM;
Proposition 6: SET OPERATORS:
1. UNION / UNION ALL:
- UNION: Returns result from both queries after eliminating duplications.
e.g.: SELECT employee_id, job_id
FROM employees
UNION
SELECT employee_id, job_id
FROM job_history;
- UNION ALL: returns results from both queries, including all duplications.
2. INTERSECT:
e.g.: SELECT employee_id, job_id
FROM employees
INTERSECT
SELECT employee_id, job_id
14
FROM job_history;
3. MINUS:
e.g.: SELECT employee_id, job_id
FROM employees
MINUS
SELECT employee_id, job_id
FROM job_history;
Conclusion:
This practical covers topics:
- how to use DML statements and control transactions.
- how to create and manage tables and adding constraints to existing tables.
- how to derive views.
- DCL statements that control access to the database and database objects.
- how to use SET operators.
QUESTIONS:
The following questions are all based on the university schema.
1. Find the number of instructors who have never taught any course. If the
result of your query is empty, add appropriate data (and include
corresponding insert statements) to ensure the result is not empty.
15
3. Find the maximum number of teachers for any single course section.
Your output should be a single number. For example if CS-101 section 1
in Spring 2012 had 3 instructors teaching the course, and no other
section had more instructors teaching the section.
4. Find all departments that have at least one instructor, and list the names
of the departments along with the number of instructors; order the
result in descending order of number of instructors.
6. For each student, compute the total credits they have successfully
completed, i.e. total credits of courses they have taken, for which they
16
have a non-null grade other than 'F'. Do NOT use the tot_creds attribute
of student.
7. Find the number of students who have been taught (at any time) by an
instructor named 'Srinivasan'. Make sure you count a student only once
even if the student has taken more than one course from Srinivasan.
8. Find the name of all instructors who get the highest salary in their
department.
9. Find all students who have taken all courses taken by instructor
'Srinivasan'. (This is the division operation of relational algebra.) You
can implement it by counting the number of courses taught by
Srinivasan, and for each student (i.e. group by student), find the number
of courses taken by that student, which were taught by Srinivasan. Make
sure to count each course ID only once.
17
10.Find the total money spent by each department for salaries of instructors
of that department.
11. Find the names of all students whose advisor has taught the maximum
number of courses (multiple offerings of a course count as only 1).
(Note: this is a complex query, break it into parts by using the with
clause.)
Remark:
Grade:
18
Experiment no: - 4
Title: Schema creation and constraints
Resources required:
Oracle 9i - iSQLplus onwards or Postgesql
Theory:
drop
drop
drop
drop
table
table
table
table
trainhalts;
train;
track;
station;
19
from
from
from
from
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
trainhalts;
station;
track;
train;
station values ('CST' ,'MUMBAI');
station values ('BYC' ,'BYCULLA');
station values ('DR' ,'DADAR');
station values ('KRL' ,'KURLA');
station values ('GPR' ,'GHATKOPAR');
station values ('TNA' ,'THANE');
station values ('DL' ,'DOMBIVALI');
station values ('AMR' , 'AMBARNATH');
station values ('KYN' ,'KALYAN');
station values ('KSR' ,'KASARA');
train values ('KP11' ,'CST-KYN');
train values ('KP11L' ,'CST-KYN_LOCAL');
train values ('T129' ,'CST-TNA_LOCAL');
train values ('A63' ,'CST-DL_LOCAL');
train values ('K101' ,'CST-KYN_LOCAL');
train values ('N27' ,'CST-TNA_LOCAL');
train values ('S33' ,'CST-KGR_LOCAL');
train values ('A65' ,'CST-AMR_LOCAL');
track values ('CST' ,'BYC', 5);
track values ('CST' ,'DR', 9);
track values ('CST' ,'KRL', 16);
track values ('CST' ,'GPR', 20);
track values ('CST' ,'TNA', 34);
track values ('CST' ,'DL', 49);
track values ('CST' ,'KYN', 54);
track values ('CST' ,'KSR', 77);
track values ('CST' ,'AMR', 65);
track values ('BYC' ,'DR', 4);
track values ('BYC' ,'KRL', 11);
track values ('GRP' ,'TNA', 14);
track values ('DR' ,'TNA', 25);
track values ('KRL' ,'KYN', 38);
track values ('TNA' ,'KYN', 20);
track values ('TNA' ,'KSR', 43);
trainhalts values ('KP11' , 0 , 'CST' , NULL, '20.23');
trainhalts values ('KP11' , 1 , 'BYC' , '20.31', '20.32');
trainhalts values ('KP11' , 2 , 'DR' , '20.41', '20.42');
trainhalts values ('KP11' , 3 , 'GPR' , '20.52', '20.53');
trainhalts values ('KP11' , 4 , 'GPR' , '20.52', '20.53');
trainhalts values ('KP11' , 5 , 'DR' , '20.41', '20.42');
trainhalts values ('KP11' , 6 , 'GPR' , '20.58', '20.59');
trainhalts values ('KP11' , 7 , 'TNA' , '21.21', '21.22');
trainhalts values ('KP11' , 8 , 'DL' , '21.45', '21.46');
trainhalts values ('KP11' , 9 , 'KYN' , '21.54', NULL);
trainhalts values ('A65' , 0 , 'CST' , NULL , '20.52');
trainhalts values ('A65' , 1 , 'BYC' , '21.00' , '21.01');
trainhalts values ('A65' , 2 , 'DR' , '21.10' , '21.11');
trainhalts values ('A65' , 3 , 'KRL' , '21.22' , '21.23');
trainhalts values ('A65' , 4 , 'GPR' , '21.28' , '21.29');
trainhalts values ('A65' , 5 , 'TNA' , '21.49' , '21.50');
trainhalts values ('A65' , 6 , 'DL' , '22.13' , '22.14');
20
Questions:
Write the following Queries for Railway Schema
1. Find pairs of stations (station codes) that have a track (direct connection) with
distance less than 20Kms between them.
2. Find the IDs of all the trains which have a stop at THANE
5. Find the name of the trains which have stop at Thane, before the 6th station in the
route of the train.
21
6. Modify the trains schema which we saw earlier to create constraints to check the
following:
1. The value of timein is always less than or equal to timeout
8. Write SQL Create table statements to create the following schema. Include all
appropriate primary and foreign key declarations. Choose appropriate types for
each attribute.
1. remotecentre(centreId, college, town, state)
22
Remark:
Grade:
Experiment no: - 5
23
TITLE:
Performing practical by using Object-oriented database concepts.
RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql
PRIOR CONCEPTS:
Basic SQL Statements and Object-Oriented Programming Concepts.
NEW CONCEPTS:
Objects User defined complex data types
An object has structure or state (variables) and methods (behavior/operations).
Object Oriented Database Management Systems:
as distribution & high performance access. OODB are queried using a standard Object
Query Language (OQL).
Object Query Language (OQL) is a query language standard for object-oriented
databases modelled after SQL. OQL was developed by the Object Data
Management Group (ODMG). Because of its overall complexity no vendor has
ever fully implemented the complete OQL. OQL has influenced the design of
some of the newer query languages like JDOQL and EJBQL, but they can't be
considered as different flavours of OQL.
Key Differences between OQL and SQL
OQL differs from SQL in that:
OQL supports object referencing within tables. Objects can be nested within
objects.
Not all SQL keywords are supported within OQL. Keywords that are not relevant
to Netcool/Precision IP have been removed from the syntax.
OQL can perform mathematical computations within OQL statements.
Query returns:
OQL
SQL
Object
Collection of objects
Tuple
Table
Complex Object:
It can be composed of multiple base or user defined datatypes. They can represent
complex internal structure attributes & behavior. To create a complex object ,need to:
- Construct new user-defined datatypes (UDTs).
- Define new user-defined datatypes (UDFs).
To manipulate these types. Composite datatype consists of collection of values.
25
);
Table:
CREATE TABLE build1 (
BuildID NUMBER,
Name VARCHAR2 (50),
Units Apt_list1);
26
Conclusion:
Thus we learned Object-oriented concept, in that how to create UDT and define
data .
QUESTIONS:
Using Object Oriented databases create the following types:
a)AddrType1 (Pincode: number, Street :char, City : char,. state :char)
27
g) authors of AuthorType
i) Publishers of PublisherType
Insert 10 records into the above tables and fire the following queries:
28
1.List all of the authors that have the same pin code as their publisher:
3. List the name of the publisher that has the most branches
5. List all authors who have published more than one book:
6. Name of authors who have published books with at least two different publishers
29
7. List all books (title) where the same author appears more than once on the list of
authors (assuming that an integrity constraint requiring that the name of an author is
unique in a list of authors has not been specified).
Remark:
Grade:
Experiment no: - 6
30
TITLE:
Performing practical by using using fragmentation concept.
RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql
PRIOR CONCEPTS:
Relational database and Basic SQL Statements.
NEW CONCEPTS:
Definition of Distributed Database:
A distributed database is a database that is under the control of a central database
management system (DBMS) in which storage devices are not all attached to a common
CPU. It may be stored in multiple computers located in the same physical location, or
may be dispersed over a network of interconnected computers. The computers in a DDB
system known as sites or nodes may vary in size and function.
The DDBMS synchronizes all the data periodically and, in cases where multiple
users must access the same data, ensures that updates and deletes performed on the data
at one location will be automatically reflected in the data stored elsewhere.
The general structure of a distributed system is:
Data Distribution:
31
Data Fragmentation:
In this scheme, the relation is divided into fragments. The partitioning of relations
is known as fragmentation. It allows a subset of the relations attributes or relations tuple
to be defined at a given site to satisfy local applications.
There are various ways of data fragmentation:
-
Horizontal Fragmentation
Vertical Fragmentation
Mixed Fragmentation.
32
Examples:
Proposition 1: Vertical Fragmentation:
EMP (EMP#, Name, Dept, Degree, Phone, Sal, StartDate)
Fragment this relation vertically; into two different relations/nodes
EMP1 (EMP#, Name, Degree, Phone)
EMP2 (EMP#, Name, Sal, StartDate)
-
MODULE:
USES:
33
TID MODULE
T1 Query Processing
T2 User Interface
TID USES
T1 SORT
T2 SORT
Proposition
2:
Horizontal Fragmentation:
AcctNo.
A-1
A-2
A-3
A-4
Balance
500
300
400
600
ACCT1:
Branch_name AcctNo.
V
A-2
V
A-4
Balance
300
600
ACCT2:
Branch_name
H
H
AcctNo.
A-1
A-3
Balance
500
400
Conclusion:
Thus we learned horizontal & vertical fragmentation concept of distributed
database.
34
QUESTIONS:
1. Create a global conceptual schema Emp(Eno;Ename;Address;Email;Salary) and
insert 10 records. Divide Emp into vertical fragments Emp1 (Eno; Ename;
Address) and Emp2 (Eno; Email; Salary) on two different nodes.
(i)
Find the salary of an employee where employee number is
known.
(ii)
(iii)
(iv)
35
c) Find the employee name and Email where employee number is known.
d) Find the employee name and address where employee number is known.
Remark:
Grade:
36
Experiment no: - 7
TITLE:
Performing practical by using replication concepts
RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql
PRIOR CONCEPTS:
Relational database and Distributed database concept.
NEW CONCEPTS:
Replication:
Replication is the process of creating and maintaining replica versions of database
objects (e.g. tables) in a distributed database system.
Replication can improve performance and increase availability of applications
because alternate data access options becomes available. For example, users can access a
local database rather than a remote server to minimize network traffic. Furthermore, the
application can continue to function if parts of the distributed database are down as
replicas of the data might still accessible.
Data Replication
- Storage of data copies at multiple sites served by a computer network
- Fragment copies can be stored at several sites to serve specific information
requirements
- Can enhance data availability and response time
- Can help to reduce communication and total query costs
37
Replication Objects:
A replication object is a database object existing on multiple servers in a
distributed database system. In a replication environment, any updates made to a
replication object at one site are applied to the copies at all other sites. Advanced
Replication enables you to replicate the following types of objects:
Tables
Indexes
Views and Object Views
Packages and Package Bodies
Procedures and Functions
User-Defined Types and Type Bodies
Triggers
Synonyms
Indextypes
User-Defined Operators
Regarding tables, replication supports advanced features such as partitioned tables, indexorganized tables, tables containing columns that are based on user-defined types, and
object tables.
Replication can be done by three ways:
1) Views
2) Synonym
3) Snapshot
Comparison :
38
1) View & Synonym doesnt store their own data but the derived the data from the
base table from where the view & synonym has been made whereas snapshot has
its own data
2) Again view & synonym requires continuously link but it can be refereshed at
periodic intervals.
3) View is basically used for in-house purpose whereas synonym & snapshot are
basically used in distributed database.
4) Snapshot is read only.
5) You must have to create a primary key before snapshot created.
Proposition 1: How does one implement basic snapshot replication?
Start by creating an optional snapshot log on the master database. If you do not
want to do fast refresh, you do not need to create a log. Also note that fast refreshes are
not supported for complex queries. Create a snapshot/materialized view on the snapshot
site. Look at this example:
SQL> create materialized view emp
refresh fast with primary key
start with sysdate
next sysdate + 1/(24*60)
as (select * from emp);
2. Connect boss/boss
Create table exp as select * from emp;
Grant all on emp to public;
Also grant all on exp to public;
Connect client/client;
Conclusion:
Thus we learned how to implement replication concept by using
two users.
40
QUESTIONS:
Create a global conceptual schema EMP (Eno; Ename; Address; Email; Salary) and insert
10 records. Store the replication of EMP into two different nodes and fire the following
queries:
(i) Find the salary of all employees.
(iii) Find the employee name and Email where employee number is known.
(iv) Find the employee name and address where employee number is known.
Remark:
Grade:
Experiment no: - 8
Title: Study of data warehousing tool.
Resources required:
Remark:
Grade:
42
Experiment no: - 9
Mini Projects:
Resources required:
Problem Statement:
Remark:
Grade:
43
Experiment no: - 10
Mini Projects:
Resources required:
Problem Statement:
Remark:
Grade:
44
Assignments
45