+ All Categories
Home > Documents > combined six expt.docx

combined six expt.docx

Date post: 02-Nov-2014
Category:
Upload: vns4486
View: 105 times
Download: 0 times
Share this document with a friend
Popular Tags:
45
Relational Database Management System (17332) Experiment No: 1.2 EXPERIMENT NO. 1.2 1.0 Title: Design and normalize a database up to three normalization form 2.0 Prior Concepts: Database, Relations, Tables, Tuples, Attributes, Domain, Primary key, Foreign Key, Entity, ER diagrams 3.0 New Concepts: Proposition 1: Normalization : Normalization is a body of rules addressing analysis and conversion of data structures into relations. Resultant relation exhibit more desirable properties of internal consistency, minimal redundancy and maximum stability. Proposition 2 : Different forms of Normalization Dr Codd, founder of relational databases has defined them as First, Second and Third normal forms. Later Boyce Codd Normal form (BCNF), fourth and fifth normal forms are derived. Proposition 3 : Normalization Process. Normalization process best can be explained with the example. The following example will be used to explain First, Second and Third normal forms. Consider the data structure of an order as it appears on an order form. Order 1. orderno 2. orderdate 3. customerno 4. itemno 5. itemname 6. qtyordered As many as items ordered in the order 7. rateperunit 8. itemvalue Order has unique order number. Order date is the date on which date the order is placed by a customer having customer number. One or more items may be ordered in an order which would contain details of multiple items. Item value is qtyordered multiplied by rateperunit. Rate per unit is independent of itemno or itemname. Proposition 4: First Normal Form : A relation is in the first normal form if it does not contain any repeating elements groups. The domain of an attribute must have atomic values. Since above example does contain repeating groups of item details, hence it is not in first normal form. To convert a relation into the first normal form remove all repeating (or multivalued) attributes to another (child) relation. MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Transcript
Page 1: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

EXPERIMENT NO. 1.2

1.0 Title:Design and normalize a database up to three normalization form

2.0 Prior Concepts: Database, Relations, Tables, Tuples, Attributes, Domain, Primary key, Foreign Key, Entity, ER diagrams

3.0 New Concepts:

Proposition 1: Normalization : Normalization is a body of rules addressing analysis and conversion of data structures into relations. Resultant relation exhibit more desirable properties of internal consistency, minimal redundancy and maximum stability.

Proposition 2 : Different forms of NormalizationDr Codd, founder of relational databases has defined them as First, Second and Third normal forms. Later Boyce Codd Normal form (BCNF), fourth and fifth normal forms are derived.

Proposition 3 : Normalization Process.Normalization process best can be explained with the example. The following example will be used to explain First, Second and Third normal forms. Consider the data structure of an order as it appears on an order form.

Order1. orderno2. orderdate3. customerno4. itemno5. itemname6. qtyordered As many as items ordered in the order7. rateperunit8. itemvalue

Order has unique order number. Order date is the date on which date the order is placed by a customer having customer number. One or more items may be ordered in an order which would contain details of multiple items. Item value is qtyordered multiplied by rateperunit. Rate per unit is independent of itemno or itemname.

Proposition 4: First Normal Form : A relation is in the first normal form if it does not contain any repeating elements groups. The domain of an attribute must have atomic values.Since above example does contain repeating groups of item details, hence it is not in first normal form. To convert a relation into the first normal form remove all repeating (or multivalued) attributes to another (child) relation. Above order relation can be split into two relations order and orderitem as follows.Order Orderitemorderno (Primary key) ordernoorderdate itemnocustomerno itemname

qtyordered rateperunit

itemvalue

Here key element orderno had to be duplicated in the orderitem relation. It facilitates the linking of the rows in the orderitem relation to the rows in the order table.After eliminated repeating element or groups in both the tables, these relations are now in the First Normal Form

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Primary key

Page 2: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Proposition 5: Second Normal FormA relation is in the second normal form if it is in the First normal form and all non key attributes are fully

functionally dependent on the primary key.If we examine the orderitem relation we find that itemname is not fully functionally dependent on the full

primary key (orderno + itemno) as it is functionally dependent on partial key itemno. Here it is not necessary to know orderno to determine itemname as we can determine it from itemno alone.Advantage: Second normal form simplifies the anomalies such as insert, update and delete operations. If name and item is changed then it has to be changed in all item rows where it occurs. If not taken care database will not be in consistent state. Thus a relation in 1NF can be converted into 2NF by removing attributes that are not dependent on the full primary key.

Proposition 6:Third Normal Form :A relation is in the third normal form if it in the second normal form and every non key attributes is non transitively dependent on primary key or a relation is in third normal form, if it is in 2 NF and every attribute is independent on other non key attribute.If we examine orderitem relation. It is clear that item value can be derived from Qtyorder and rateperunit

hence each of these three attributes dependent on other two attributes, thus we can transfer 2NF into 3NFas

Orderitem *orderno*Itemno QtyorderedRateperunit

We could have removed one out of three by keeping other two. Normalization rules does not specify which to discard and which to retain.

Thus our original relation order is now transformed into three relations as shown below.Order Order item item*Orderno Orderno *itemnoOrderrate itemno itemname CustomerNo Qtyordered

Rateperunit4.0 Learning Objectives :

Intellectual Skills :

1. Understand the basics of a database2. Organize the data by applying normalization rules

Motor Skills :

1. Ability to handle keyboard and mouse. 2. Ability to work with editor. 3. Ability to draw and represent separate entities

5.0 Sample Examples : 5.1 Following table shows student code, student name and percentage, their multiple courses and their marks

as shown in marks table format. Whether this table in NF? How to convert this table into a normalized table.

Student code

S1 C1-86, C2-45, C3,48, C4,58, C5,62, per 59.8S2 C1,59, C3,72, C5,68, per 66.33

S3 C1,56 per 66

(fig-1)If S1, S2, S3 are the students having names Rajat Bhatia, Meenal Joshi and Sopan Patil respectively. Also

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Primary key

Page 3: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

the C1, C2, C3, C4, C5 are the courses having names as English, Mathematics, Physics, Statistics and Accounting respectively. How will you design the tables by applying rules of normalization? Identify the primary key and foreign key of each table. Database must be normalized to minimum of 3NF.(Note: this normalized database is to be used in experiment no.9)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

6.0 Questions for confirmation of LearningFill in the blanks (join, atomic, functional, multivariate, transitive)

1. 1NF contains ----------------- values.

2. 2NF removes ----------------- dependencies.

3. 3NF remove ----------------- dependencies.

4. 4NF eliminates ----------------- dependencies.

5. 5NF removes ----------------- dependencies.

7.0 Students Activity1. Can figure-1 be represented in the form of figure2 as shown? Whether figure2 in 1NF? If yes what are the

advantages and disadvantages? Why this design practically not considered.

Student Course1 M1 course2 M2 Course3 M3 course4 M4 course5 M5

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 4: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

codeS1 C1 86 C2 45 C3 48 C4 58 C5 62

S2 C1 59 - - C3 72 - - C5 67

S3 C1 56 - - - - - - - -

(figure2)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

8.0 Questions1. What is normalization? What is its advantage?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2. Define functional dependency?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

3. What is the minimum level of normalization data base designers aimed at? Why?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4. Define BCNF. Explain with appropriate example.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 5: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

C (4) P (4) A(2) T (10) Signature of Teacher

EXPERIMENT NO. 4.1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 6: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

1.0 Title:

Write and execute queries using arithmetic, comparison and logical operators

2.0 Prior Concepts:

Data Manipulation Language (DML)

3.0 New Concepts:

Proposition 1 : Operator:An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations

Proposition 2 : Types of Operators :

There are three types of operators:

1. Arithmetic Operators. 2. Comparison / relational Operators. 3. Logical Operators.

Proposition 3 : Arithmetic Operators :

Operator Description Example Precedence- Negation -sal 1+ Identity +sal 1* Multiplication sal * 1.1 2/ Division sal / 12 2+ Addition sal + comm. 3- Subtraction sal – comm. 3

Proposition 4 : Comparison Operators :

It is used to compare one expression with another using comparison operators.SQL uses either symbolic operators or predicates (word comparison) operators

SQL's Comparison Operators

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 7: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

symbol Use Description Example= a = b Equal to, Tests for equality of two operands. select * from emp

where sal =500 !=^=<>

a != ba ^= ba <> b

Not equal to, Tests for inequality of two operands. Can use any one.

select * from emp where sal !=500

< a < b Less than, Tests that operand a is less than operand b.

select * from emp where sal <500

!< a !< b Not less than, Tests that operand a is not less than operand b. This is the same as >=.

select * from emp where sal !<500

> a > b Greater than, Tests that operand a is greater than operand b.

select * from emp where sal >500

!> a !> b Not greater than, Tests that operand a is not greater than operand b. This is the same as <=.

select * from emp where sal !>500

<= a <= b Less than equal to,Tests that operand a is less than or equal to operand b. This is the same as !>.

select * from emp where sal <=500

>= a >= b Greater than equal to, Tests that operand a is greater than or equal to operand b. This is the same as !<.

select * from emp where sal >=500

Word Comparison operatorsKeyword Use Description ExampleIN a IN (b,c...) Tests that operand a matches at least one

element of the list provided (operand b, operand c, etc.).

select * from emp where sal in (500,600,700)

NOT IN a NOT IN (b,c...)

Tests that operand a does not match any element of the list provided (operand b, operand c, etc.).

select * from emp where sal not in (500,600,700)

ANY a = ANY (b,c...) a < ANY (b,c...) a > ANY (b,c...), etc.

Tests that the relationship specified (e.g., =, <>, <, >, etc.) is true for at least one element of the list provided (operand b, operand c, etc.). When testing for equality, this is equivalent to IN.

select * from emp where sal = any (500,600,700)

SOME a = SOME (b,c...) a < SOME (b,c...) a > SOME (b,c...), etc.

Tests that the relationship specified (e.g., =, <>, <, >, etc.) is true for at least one element of the list provided (operand b, operand c, etc.). When testing for equality, this is equivalent to IN.

select * from emp where sal = some (500,600,700)

ALL a = ALL (b,c...) a < ALL (b,c...) a > ALL (b,c...), etc.

Tests that the relationship specified (e.g., =, <>, <, >, etc.) is true for every element of the list provided (operand b, operand c, etc.).

select * from emp where sal > all (500,600,700)

BETWEEN a BETWEEN b and c

Tests that operand a is greater than or equal to operand b and less than or equal to operand c. The range which is specified will contain min value and max value. It is used for numeric and date data type

select * from emp where sal between 400 and 600

NOT BETWEEN

a NOT BETWEEN b and c

Tests that operand a is less than operand b or greater than operand c. It test the range other than b to c

select * from emp where sal not between 400 and 600

EXISTS EXISTS (query)

Tests that the query returns at least one row. select * from emp e where exists (select deptno from dept d where deptno= e.deptno)

NOT EXISTS

NOT EXISTS

Tests that the query does not return a row. select * from emp e where not exists (select

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 8: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

(query) deptno from dept d where deptno=e.deptno)

LIKE a LIKE b Tests that operand a matches pattern operand b. The pattern may contain ‘_’ which matches a single character in that position, or ‘%’ which matches all characters.

Select * from emp where ename like `smi%'

NOT LIKE a NOT LIKE b

Tests that operand a does not match pattern operand b. The pattern may contain _, which matches a single character in that position, or %, which matches all characters.

select * from emp where ename not like `smi%'

IS NULL a IS NULL Tests that operand a is NULL. Null value means no value or an unavailable, unassigned, unequal to any value or zero length of string in a data cell

select * from emp where comm is null

IS NOT NULL

a IS NOT NULL

Tests that operand a is not NULL. select * from emp where comm is not null

Proposition 5: Logical Operator: Logical operators that are similar to those available in most other programming languages. The logical operators AND and OR combine the results of two Boolean values to produce a single result based on them, while the logical operator NOT inverts a result. The Boolean values may be any expression that can be evaluated to TRUE or FALSE.

Operator Use Description Example AND Exp1 AND

exp2AND means expression is true if and only if both exp1 and exp2 are true

Select * from emp where sal >10000 and job=’Clerk’

OR Exp1 ORexp2

OR means expression is true if either of exp1 or exp2 or both are true

Select * from emp where sal >10000 or job=’Clerk’

NOT NOT exp If expression is true not make it false or vice versa

Select * from emp where NOT (sal >10000)

4.0 Learning Objectives:

Intellectual Skills:

3. Understand the use of DML commands.

4. Understand the use of operators.

Motor Skills:

4. Ability to handle keyboard and mouse.

5. Ability to work with editor.

5.2 Sample Examples :

Write the queries for the following and write the output in the space provided. If output is more than two rows write only first two rows. Show columns as they appear in output

5.1 Display unique jobs from emp table

SQL> Select distinct (job) from emp;

Output

5.2 List the employees whose salary is more than 3000 after giving 20% increment

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 9: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

SQL> Select EMP.*, SAL+ (SAL*.2) incrsal from emp where SAL+(SAL*.2) >3000;

Output

5.3 List the employees, department number who does not belong to department 20

SQL>

Output

5.4 List the employee name, salary whose annual salary does not fall from 22000 to 45000

SQL>

Output

5.5 List all employee number, employees, job, joined before 1981

SQL>

Output

5.6 List all the employee numbers, employees, job except ‘President’ & ‘Mgr’

SQL>

Output

5.7 Display names all employees whose name is 5 characters long

SQL>

Output

5.8 Display all employees working under manager John or salary greater than 20000

SQL>

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 10: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

5.9 Write query to get output in following format

SQL>

Output Empno Ename jobs Sal Daily salary Annual salary

5.10 Display the name of employee who does not work under any manager

SQL>

Output

6.0 Questions for confirmation of Learning:

6.1 Write the above query number 5.4 by using other operator? What are the options to check range of values

SQL>

6.2 What NULL data type represents? Why it is used? How to check values for NULL?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

7.0 Students Activity

7.1 Create the following table with appropriate data types and add the data in the table as shown.

8.0 Questions Client TableClient no. Name City Pincode State Balance due

C001 Vikas Jain Mumbai 400054 Maharashtra 15000

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 11: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

C002 V Chandran Chennai 780001 Tamilnadu 0

C003 Pramod Patil Mumbai 400057 Maharashtra 5000

C004 Jatin Sapru Mumbai 400056 Maharashtra 0

C005 Virat Kohli Delhi 100001 2000

C006 Vilas Pendse Mumbai 400050 Maharashtra 0

Write the queries for the following and write the output as displayed:8.1 Find the names of all clients and their city.

SQL>

Output

8.2 Find all the clients having ‘i’ as second letter in their name

SQL>

Output

8.3 Find all the clients who does not stay in Mumbai OR Chennai

SQL>

Output

8.4 Print all the clients whose balance due is greater than value 10000..

SQL>

Output

8.5 . Display all clients having balance below 2000 and above 3000

SQL>

Output

8.6 List all names having name consist of five alphabets only

SQL>

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 12: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

8.7 List the information of client whose state is unknown.

SQL>

Output

8.8 Find distinct cities of clients

SQL>

Output

8.9 Find the revised baldue if 20 % discount is given to each client

SQL>

Output

8.10 Write a procedure to Create output file client. For (1) Spool the output of all above queries in to a text file client. (2) Set the default editor to notepad.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SQL>

SQL>

C (4) P (4) A(2) T (10) Signature of Teacher

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 13: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

EXPERIMENT No. 4.2

1.0 Title:

Write and execute the queries using string and numeric functions

2.0 Prior Concepts:

Data Manipulation Language (DML), operators in SQL

3.0 New Concepts:Proposition 1:Function: Functions are the ready to use code written and tested by expert. User just need to know how to use it by passing the required value and get the required answer. It may have one or more argument and return a valueCharacter functions: It accepts character input and returns either character or number.

Function Name Description

Initcap(char) Returns the input string with initial letter capitalized and all other character in lower case.

Lower(char) Returns the input string with all letters in lower case.

Upper(char) Returns the input string with all letters in Upper case.

Ltrim(char,set) It removes or trims from the left of character string.

Length(char) It returns the length of character string.

Chr(n), Returns a character binary equivalent of n

Ascii(char) Returns a decimal representation of a character

Rtrim(char,set) It removes or trims specified set from the right of character string.

Substr(char,m,n) It returns a portion of char, beginning at a character m, n character long, m can be +ve or –ve, n cannot be less than 1.

Instr(char1, char2,[,n [m]] Searches char 1 beginning with its nth character for the mth occurrence of char2 and return the position of character .i.e. the first character of this occurrence.

Replace(char, searchstring, [repstring])

It returns character string with each occurrence of searchstring replaced with [repstring].

Translate(char, from, to) It returns char with all occurrences of each character in from replaced by its corresponding character in to. Character in char that are not in from are not replaced.

Lpad(char1,length,char2) It returns char 1 left-padded to given length with the sequence of characters in char 2;

Rpad (char1,length,char2) It returns char 1 right-padded to given length with the sequence of characters in char 2;

Concat(char1, char2) Char 1 is concatenated to char 2 It merges two or more string value together. It is similar to concatenation operator ||

Soundex(char) Returns a character string containing the phonetic representation of char. This allows to compare words that are spelled differently but sound alike in English

Numeric Functions:Numeric Functions accepts the numeric value as the input and it returns the numeric value as the output

Function Name Description

Abs(n) (Where n is a number)

Returns the absolute value of the n

Power(m ,n) It returns m raised to nth power.

Mod(m, n) Returns the reminder of m divided by n.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 14: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Sqrt(n) It returns square root of n. n cannot be negative

Exp(n) Returns the e raised to power of the n.

Round(n,[ m]) Returns n rounded to m places right of the decimal point.

Trunc(n, m) Returns n truncated to m decimal places.

Ceil(n) Returns the smallest integer that is greater or equal to n.

Floor(n) Returns the largest integer that is equal or less than n.

Cos(n) Returns the cosine of the n.

Cosh(n) Returns the hyperbolic cosine of the n

Sin(n) Returns the sine of the n.

Sinh(n) Returns the hyperbolic sine of the n

Tan(n) Returns the tangent of the n.

Greatest(expr, [expr], …) Return the greatest of list of expression

Least(expr, [expr], …) Return the least of list of expression

4.0 Learning Objectives :

Intellectual Skills :

5. Understand the use of DML commands.

6. Understand the use of operators with arithmetic and string function7. Use arithmetic and string functions.

Motor Skills :

6. Ability to handle keyboard and mouse.

7. Ability to work with editor.

5.3 Sample Examples :

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 15: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

W

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Character Functions

S.No. Example Output

1 Select initcap(ename)from emp where empno=7369;

2 Select lower(‘HELLO’)from dual;

3 Select lower(ename)from emp where empno=7369;

4 Select upper(‘Hello’)from dual;

5 Select upper(ename)from emp where empno=7369;

6 Select ltrim(‘Rajesh’,’Raj’)from dual;

7 Select ltrim(ename,’Raj’),from emp where empno=7369 ;

8 Select rtrim(ename,’sh’) from emp where empno=7369;

9 Select length(dname) from dept where deptno=20;

10 Select chr(65) from dual;

11 Select ascii(‘A’) from dual;

12 Select substr (ename,1,3)from dept;

13 Select ename, instr(ename,’jesh’) from emp where empno=7369;

14 Select replace(‘Tick and Tack’,’T’,’C’)from dual;

15 Select replace(ename,’Ra’,’xy’) from emp;

16 Select translate(ename,’a’,’i’)from emp where empno=7782;

17 Select lpad(ename,10,’*’), rpad(ename,10,’*’) from emp;

18 Select ename from emp where soundex(ename) =soundex(‘Rokesh) where empno=7839;

19 Select ename || ‘ ‘ || job from emp where empno=7369;

20 select concat (concat (ename, ' is a '),job) from emp where sal > 50000;

Numeric Functions

S.No. Example Output

1 Select abs(-7.5) from dual;

2 Select power( 2,10) from dual;

3 Select mod(11,3) from dual;

4 Select sqrt(64) from dual;

5 Select exp(2) from dual

6 Select sal, round(sal,-3) from emp where empno=7369;

7 Select sal, trunc(sal,-3) from emp where empno=7369;

8 Select ceil(14.3) from dual;

9 Select floor(14.7) from dual;

10 Select sin(90) , cos(0) from dual;

11 Select tan(45) acos(90) from dual;

12 Select sal,greatest(sal,500) from dual;

13 Select sal, least(sal, 1000) from dual;

Page 16: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

6.0 Questions for confirmation of Learning: 6.1 Write the query to get the output in following statement

7566 employee number belongs to employee name --------, who works as ------------ of department number ----- and joined on ------- having salary ---------

Sql>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

6.2 What is dual table? What it contains? How it works? Why it is provided- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

6.3 State difference between following with help of example:Replace Translate

Floor Ceil

Round Truncate

7.0 Students Activity: Write the queries and output for the following

7.1 Write a single query to display your best friend’s name

SQL>

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 17: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Output

7.2Find the data of employee ‘vijay’ in emp table irrespective of how it is stored in a table (Vijay,

VIJAY etc)

SQL>

Output

7.3 Display the data for those employees whose last names end with an n.

SQL>

Output

7.4 calculates the remainder of the salary after dividing it by 5,000

SQL>

Output

7.5 Display the salary of employees rounded to 1000 only

SQL>

Output

7.6

Produce the following output from EMP

EMPLOYEE

----------------

SMITH(clerk)

SQL> select ename || '(' || lower(job) ||')' EMPLOYEE from emp

Output

7.7 List all the 4 character employees.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 18: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

SQL> SQL>Select ename from emp having length (ename) = 4

Output

7.8 List first 50% of chars of ename in lower case

SQL> select ename, lower(substr(ename,1,length(ename)/2))

Output

C (4) P (4) A(2) T (10) Signature of Teacher

EXPERIMENT No. 5

1.0 Title:

Learn and use different date formats, date functions and data type conversion from one type to another

2.0 Prior Concepts:

Data Manipulation Language (DML), operators in SQL

3.0 New Concepts:Proposition 1: Date and time formats: Default data for date type is ‘DD-MMM-YY’, Once data stored in date formats it can be displayed in any format by combination of one or more data formats as shown in following table.

Format mask DescriptionCC or SCC Century prefixes BC dates with ‘-‘YYYY or SYYY Year with 4 digit number, prefixes BC dates with ‘-‘ YYY, YY, Y Year with 3, or 2 or 1 digit RR Year with 2 numbers with Y2k compatibility YEAR Year in characters BC BC/AD Indicator * Q Quarter in numbers (1,2,3,4) MM Month of year 01, 02...12 MONTH Month in characters (i.e. January) MON JAN, FEB WW Week number (i.e. 1) W Week number of the month (i.e. 5) DDD Day of year in numbers (i.e. 365) DD Day of the month in numbers (i.e. 28) D Day of week in numbers(i.e. 7) DAY Day of the week in characters (i.e. Monday) DY Day of the week in short character description (i.e. SUN) J Julian Day (number of days since January 1 4713 BC, where January 1 4713

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 19: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

BC is 1 in Oracle) HH Hour number of the day (1-12) HH12 Hour number of the day (1-12) HH24 Hour number of the day with 24Hours notation (0-23) AM or PM AM or PM, Meridian IndicatorMI Number of minutes (i.e. 59) SS Number of seconds (i.e. 59) SSSSS Number of seconds this day. RM The Roman numeral representation of the month (I .. XII) SP Spelled format. Can appear of the end of a number element. The result is

always in english. For example month 10 in format MMSP returns "ten" SPTH Spelled and ordinal format; 1 results in first. TH Converts a number to it's ordinal format. For example 1 becoms 1st. TS Short time format. Depends on NLS-settings. Use only with timestamp.

Number fmt modelFormat Description99999 5-digits integer999,999.99 6-digit value with 2-digit decimal0999,999.99 zero-fill column B999,999.99 blank spaces$999,999.00 dollar sign prefix

Date Manipulation Functions:Sr.No. Format Description

1. Month_between(d1,d2) where d1 and d2 are dates.

Months_between finds the number of months between d1 and d2. If date d1 is later than d2 the result is positive. If date d1 is earlier than d2 the result is negative.

2. add_months(d,n) where d-date, n-number of months to be added to the date.

Return date after addingthe number of months specified with the function.

3. next_day(d,char)where d-date,char-day of week.

Return the date of the first weekday named ‘char’ that is later than date ‘d’.

4. Last_day(d)Where d-date.

Return the last day of the month that contain date ‘d’. Used to determine how many days left in a month.

5. round(date,[fmt])where ‘fmt’-format model:MonthDayYear

Return date rounded to the unit specified by the format model ‘fmt’. If the format model ’fmt’ is omitted, date is rounded to the nearest date.

6. trunk(date,[fmt])where ‘fmt’-format model:MonthDayYear

Return date with the time portion of the day truncated to the unit specified by the format model fmt. If the format model fmt is omitted, date is truncated to the nearest day.

Data conversion functions: To use different functions such as string, numeric and date type we need to convert data into appropriate data type to pass as argument. Following are the commonly used functions for data conversion

Sr.No. Format Description1. To_date(expr,[fmt]) where fmt-

format model, expr- expression, either numbers or a character string. Fmt- is the default date fmt model.

It converts number or character string into date format.NOTE:

1) If expression is character and without format model, it must be of the form DD-MMM-YY.Number cannot be defined without format

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 20: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

model.2) Date format cannot be defined using

COLUMN command.2. To_char(expr,[fmt]) where expr –

number / date,1. if expr is date, fmt is date fmt model.2. if expr is number, fmt is number fmt model.

It converts either date or value into a character string. If ‘fmt’ is not specified and- if expr is a number, a character string long enough to accommodate the significant digits of the number is created.-if expr is a date, a string of the form DD-MMM-YY is created.GUIDELINES :

1) If a number is larger than defined format.pound sign (#)appear in place of the value.

2) Decimals are rounded off to fit into the format model.

3. To_number(char) It converts a character string containing a number into a number data type.

4.0 Learning Objectives :Intellectual Skills :8. Understand the use of DML commands. 9. Understand the use of operators.10. Use of appropriate date formats and date functions Motor Skills : 8. Ability to handle keyboard and mouse. 9. Ability to work with editor.

5.4 Sample Examples :

Date formats

S.No. Example Output

1 List the emps with hiredate in format June 4,1988SQL>select ename, to_char (hiredate,'Month DD,YYYY.') from emp

2 Display hiredate in “DD/MM/YYYY” format of first employeeSQL>

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Date Functions

S.No. Example Output

1 Select add_months(hiredate,2) from emp where empno=7369;

2 Select sysdate ( ) from dual

3 Select months_between(to_date(’02-02-2010’), ‘MM-DD-YYYY’), to _date(’01-01-2012’, ‘MM-DD-YYYY’) “Month” from dual

4 Select months_between (‘05-MAY-1996’, ‘05-JAN-1996’)“Months” from dual;

5 Select add_months(sysdate,1) from dual;

6 Select next_day(‘01-FEB-2006’, ‘Wednesday’) “next_day” from dual;

7 Select last_day(sysdate) “last” from dual;

8 Select round(sysdate, ‘day’) “round_day” from dual;

9 Select trunc(sysdate, ‘day’) “trunc_day” from dual;

Page 21: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

3 Display “20th October 1999” in the date formatSQL>

4 Display hire date in HH:MM:SS formatSQL>

5 Display date in AM/PM formatSQL>

6.0 Confirmation of Learning:8.1 Write a query to get the output as

SQL> Mr John manager of department number 30 joined on 1st MAY (Friday), Nineteen Hundred Eighty

one

Output

8.1List the emps whose exp is more than 10 years

SQL> SQL>select * from emp where months_between(sysdate,hiredate)/12 > 10

Output

7.0 Students ActivityWrite any five combinations of date format and there outputDate format Output

12345

8.0 Questions :8.1 Write a query to form a string by combining empno, ename and mgr code

SQL>

8.2 Write the output of the following

SQL> Select To_char(hiredate, ‘ddth’ “of” Month ‘yyyy’) from emp;

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Data Conversion functions

S.No. Example Output

1 Use of to_char functionSQL>select ename, to_char (hiredate,'Month DD,YYYY.') from emp

2 Use of to_date function

3 Use of to_number

4

Page 22: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

8.3 List the empno, ename, sal of all the ‘Mgrs’ and ‘Analyst’ having an experience more than 7 years

SQL> select empno, ename,sal from emp where job in('manager','analyst') and months_between(sysdate,hiredate)/12 > 7

Output

8.4 To convert string ‘January 01 2007’ into date:

SQL> Select To_date(‘January 01 2007’, ‘Month-dd-yyyy’) from dual;

Output

8.5 To display your own birth date as : 6th june 2013

SQL> Select stud_id, To_char(DOB, ‘mm/yyyy’) Date of Birth from stud_info;

Output

8.6 To display the salary of employee in format $99,999.

SQL>

Output

8.7 Display date in military format

SQL>

Output

8.8 Display salary with leading zero 8 digits with two decimal points

SQL>

Output

C (4) P (4) A(2) T (10) Signature of Teacher

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 23: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

EXPERIMENT NO. 6.21.0 Title :

To write and execute queries using aggregate functions. Set operators and sub queries2.0 Prior Concepts

Data manipulation language (DML), Function concept3.0 New Concepts :

Proposition 1: Aggregate/ Group functions: Aggregate functions returns result based on group of rows. Unlike single-row functions, group functions operate on sets of rows to give one result per group.These sets may be the whole table or the table split into groups

Group Functionsavg([distinct|all]n) Average value of n, ignoring null valuescount({*|[distinct|all]expr}) Number of rows, where expr evaluates to

something other than null (count all selected rows using *, including duplicates and rows with nulls)

max([distinct|all]expr) Maximum value of expr, ignoring null valuesmin([distinct|all]expr) Minimum value of expr, ignoring null valuessum([distinct|all]n) Sum values of n, ignoring null valuesstddev([distinct|all]x) Standard deviation of n, ignoring null valuesvariance([distinct|all]x) Variance of n, ignoring null values

Min and max functions can be used for any data type but avg, sum, variance, and stddev functions used only with numeric data types

Proposition 2: Set operators:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 24: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

AUB(union all) A ПB (intersection) A-B (minus) B-A(minus)

Operator OutputUnion The UNION operator returns results from both queries after eliminating duplications.

It is equivalent to ORUnion All All rows selected by either query, including all duplicatesIntersect Only common rows selected by both queries. Equivalent to ANDMinus All rows returned by the first query that are not present in the second

QueryRequirement: The number of columns and the data types of the columns being selected must be identical in all the SELECT statements used in the query. The names of the columns need not be identical. The output is sorted in ascending order of the first column of the SELECT clause

Proposition 3: SubqueriesSubqureis: It is a query which is embedded inside a main query or a outer query. It is also called the inner query or the subquery. It returns a value that is used by the main query. Using a subquery is equivalent to performing two sequential queries and using the result of the first query as the search value in the second query.

select ename from emp where sal > (select sal from emp where ename = ’Vijay’);Here inner query determines the salary of employee Vijay. The outer query takes theresult of the inner query and uses this result to display all the employees who earn more than this amount.

Types of subqueriesA single-row subquery is one that returns one row from the inner select statement. This type of subquery uses a single-row operator.(<, >, <=, >=, = ,<> )ExampleDisplay the employees whose job is the same as that of employee number 7788.select ename, job from emp where job = (select job from emp where empno = 7788);

Multiple-Row SubqueriesSubqueries that return more than one row are called multiple-row subqueries. Subquery uses a multiple-row operator, instead of a single-row operator( IN, ANY, ALL) , with a multiple-row subquery. The multiple-row operator expects one or more values.select ename, sal, deptno from emp where sal IN (select min(salary) from emp group by deptno);Sub queries have the following characteristics:

• Can pass one row of data to a main statement that contains a single-row operator, such as =, <>,>, >=, <, or <=

• Can pass multiple rows of data to a main statement that contains a multiple-row operator, such as IN• Are processed first by the Oracle server, and the WHERE or HAVING clause uses the results• Can contain group functions

4.0 Learning Objectives: Intellectual Skills:1. Understand concept of group functions.2. Use aggregate functions.3. Understand and use sub queries4. Write queries using sub queries

Motor Skills:1. Ability to handle keyboard and mouse

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 25: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

2. Ability to work with editor.

5.5 Sample examples on aggregate functionsSample Queries Output

Find min salary of employee

Find total salaries of employees

Find the maximum salary of employee

List the details of highest paid employeeSQL>Select * from emp where sal = (select max(sal) from emp)Find the max avg salary drawn for each job except for ‘PRESIDENT’SQL>select job, max(sal), avg(sal) from empwhere job <> 'PRESIDENT'

Find the total number of employees in emp table

Find standard deviation of salaries

Find the variance of salaries

Sample examples on set operatorsSample Queries Output

Use of Union operator: Find distinct jobs from employee and workers tableSQL>

Use of Union All operator: Find all names of employees and workersSQL>

Sample examples on sub queriesSample Queries Output

Display details of all employees having salary more than John salarySQL>select * from emp where sal > (select sal from emp where ename = 'John')

6.0 Questions for Confirmation of Learning: 1. Group functions work across many rows to produce one result per group. (True/False)2. Group functions include nulls in calculations. (True/False)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 26: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

3. Display the highest, lowest, sum, and average salary of all employees. Label the Columns Maximum, Minimum, Sum, and Average, respectively.

SQL>

Output

4. Write a query to display the last name and hire date of any employee in the same department as Savita by excluding Savita.

Queries Outputdisplay the number of employees in department 80 who can earn a commissionSQL> select count(commission_pct)from employees where department_id = 80display the number of distinct department values in the employees tablesql> select count(distinct department_id) from employees;

7.0 Student Activity Write the queries for the following8.1 Find the highest Sal of the Emp table.

SQL> Select Max(sal) from emp

Output

8.2 Find the details of highest paid employee.

SQL> Select * from emp where sal = (select Max(sal) from emp)

Output

8.3 Find the total salaries given to the managers

SQL> select sum(sal) from emp where job = 'MANAGER'

Output

8.4 Display the average salaries of all CLERKS

SQL> select avg(sal) from emp where job = 'CLERK'

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 27: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

8.5 List the details of the emps whose job is same as ALLEN

SQL> select * from emp where job = (select job from emp where ename ='ALLEN')

Output

8.6 List the emps of deptno 20 whose jobs are same as deptno 10

SQL> Select * from emp where deptno=20 and job in (select job from emp where deptno=10)

Output

8.7 List the emps whose Jobs are same as Abraham or Sal is more than Sachin.

SQL>Select * from Emp where job = (select job from emp where ename=’Abraham’) OR Sal > (select

sal from emp where ename='Sachin')

Output

C (4) P (4) A(2) T (10) Signature of Teacher

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 28: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

EXPERIMENT No. 91.0 Title:

Design and implementation of views

2.0 Prior Concepts:

Data Manipulation Language (DML), Data Definition language( DDL)

3.0 New Concepts:

Proposition 1 : Views : Logically represents subsets of data from one or more tables. A view is a logical table based on a table or another view. A view contains no data of its own but is like a window through which data from tables can be viewed or changed. The tables on which a view is based are called base tables. The view is stored as a select statement in the data dictionary. A view does not contain data. The definition of the view is stored in the data dictionary. The definition of the view is stored in the USER_VIEWS data dictionary table

Syntax to create viewscreate [or replace] view <view-name> [(<column(s)>)] as<select-statement> [with check option [constraint <name>]];The optional clause or replace re-creates the view if it already exists. A view is evaluated again each time it is accessed

Different options of View• Can be a simple view, based on one table• Can be a complex view based on more than one table or can contain groups of functions• Can replace other views with the same name• Can contain a check constraint• Can be read-only

Advantages of Views• Views restrict access to the data because the view can display selective columns from the table.• Views can be used to make simple queries to retrieve the results of complicated queries. For example,

views can be used to query information from multiple tables without the user knowing how to write a join statement.

• Views provide data independence for ad hoc users and application programs. One view can be used to retrieve data from several tables.

• Views provide groups of user’s access to data according to their particular criteria. Thus implements security and authorization.

Creating a View: Create a view, EMPVU20, that contains details of employees in department 20.

create view empvu20 as select empno, ename, sal from emp where deptno = 20;

Retrieving Data from a ViewData is retrieved from a view as you would from any table. You can display either the contents of the entire view or just specific rows and columns.Select * from empv20;

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 29: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Modifying a View: With the or replace option, view can be altered without dropping, re-creating, and regranting object privileges

Creating a Complex ViewCreate a complex view of employee and department information. Note that alternative names have been specified for the view.

Create view dept_vu (empno, ename, job, salary,deptno, dname, daddress)as select empno, ename, job, sal, deptno, dname, loc from emp, dept where emp.deptno= dept.deptno group by dept.dname;

Removing a Viewyou use the drop view statement to remove a view. the statement removes the view definition from the database. dropping views has no effect on the tables on which the view was baseddrop view viewnamerestrictions on views: you cannot remove a row from a view it contains any of the following:• group functions• a group by clause• the distinct keyword

.4.0 Learning Objectives :

Intellectual Skills :

11. Understand the benefits of views. 12. Create, modify, and remove simple and complex views.

Motor Skills :

10. Ability to handle keyboard and mouse.

11. Ability to work with editor.

5.6 Sample Examples :

Write the queries for the following and write the output in the space provided. If output is more than two rows write only first two rows. Show columns as they appear in output

5.1 Create a view called EMP_VU based on the employee numbers, employee names, and department numbers from the EMP. Change the heading for the ename name to Employee

SQL>

Output

5.2 Display the contents of the EMP_VU view.

SQL>

Output

5.3 Modifying data using view (modify the name of employee)

SQL>

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 30: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

5.4 Creating view with check constraints

SQL>

Output

5.5 Removing a view

SQL>

Output

6.0 Questions for confirmation of learning:

6.1 What is view? How it is different from base tables?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

6.2 List the operations that can be performed on views? What are its limitations

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

7.0 Students Activity7.1 Create simple view Student_vu using student table from experiment number 1.2 and complex views

SCM_CVU based on student, marks and course table. Join the three tables to display student name, course name and marks obtained from SCM_CVU views

8.0 ExerciseWrite the answers of the following

8.1 Create STUDENT_VU on student table

SQL>

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Page 31: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

8.2 Insert your name through STUDENT_VU views

SQL>

Output

8.3 Modify the record of a STUDENT_VU by changing marks or name of student

SQL>

Output

8.4 Delete the record you just added in a view STUDENT_VU

SQL>

Output

8.5 Write a query to create a complex views SCM_CVU as given in 7.2 above

SQL>

Output

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

C (4) P (4) A(2) T (10) Signature of Teacher

Page 32: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Table Details and dataBonus Table Dept Table Emp Table

Salgrade Table

Emp Table Content

Empno Ename Job Mgr Hiredate Sal Comm Deptno7369 Raj Clerk 7902 17-DEC-

1980800 Null 20

7499 Sachin Salesman 7698 20-FEB-1981

16000 300 30

7521 Ajay Salesman 7698 22-FEB-1981

12500 500 30

7566 Vijay Manager 7839 2-APR-1981

29750 Null 20

7654 Vinod Salesman 7698 28-SEP-1981

12500 1400 30

7698 John Manager 7839 1-MAY-1981

28500 Null 30

7782 Savita Manager 7839 9-JUN-1981

24500 Null 10

7788 Apurva Analyst 7566 9-DEC-1982

30000 Null 20

7839 Rakesh President Null 17-NOV-1981

50000 Null 10

7844 Shamim Salesman 7698 08-SEP-1981

15000 0 30

7876 Rahul Clerk 7788 12-JAN-1983

11000 Null 20

7900 Kalim Clerk 7698 3DEC-1981

9500 Null 30

7902 Julie Analyst 7566 3-DEC-1981

30000 Null 20

7934 Abrahham Clerk 7782 23-JAN-1982

13000 Null 10

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Grade NumberLosal Numberhisal Number

Deptno Number(2) Not Null

Dname Varchar2(14)Loc Varchar2(13)

Empno Number(4) not null

Ename Varchar2(10)Job Varchar2(9)Mgr Number(4)Hiredate DateSal Number(10,2)Comm. Number(8,2)deptno Number(2)

ename varchar2(10)Job varchar2(9)Sal Numbercomm Number

Page 33: combined six expt.docx

Relational Database Management System (17332) Experiment No: 1.2

Salgrade Table Content

Department Table

Justification Curriculum is changed Practical load changed form 2 hr /week to 4 /hr per week More practicals added in the new curriculum list on topics such as Database design concepts, ER diagrams,

Normalisation, Indexes, sequence, More exercises on PL/ SQL, Triggers implicit and explicit, Exception handling, User defined procedures and functions, Database triggers, Shared and exclusive modes of locking

All practicals are covered as per curriculum list. Practical numbers are kept same as per curriculum (i.e. from 1 to 15) But each practical is subdivided as per

the content and coverage per practical=2 Hours. Like this there will be total 22 practicals designed + two slots as practical exercise with guidelines how to use this two slots

Two slots of 2 Hours duration is kept as exercise practicals. This provision is made foro to make for holidays

o any working problems/ unavoidable circumstances

o students if absent due to genuine reasons

o cover remaining continuous assessment

o Non completion of first set of exercises

o Practice session for students difficulties

New questions are added for confirmation of learning of students New exercises added under students activity Care will be taken to formulate a query with specific answers which can be answered in given space only. No

additional pages students will require to attach to lab manual for answering exercise. As far as possible minimum standard tables will be used will be added under heading tables/ in appendix

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Deptno Dname Loc10 Accounting Mumbai20 Research Pune30 Sales Nagpur40 Operations Aurangabad

Grade Losal Hisal1 700 12002 1201 14003 1401 20004 2001 30005 3001 9999


Recommended