institute of engineering and management - … of engineering and management department of computer...

35
Database Management System Lab | Institute of Engineering and Management Department of Computer Science and Engineering Database Management Laboratory (CS 691) Lab Manual

Upload: vanduong

Post on 19-Apr-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Institute of Engineering and Management

Department of

Computer Science and Engineering Database Management Laboratory (CS 691)

Lab Manual

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Syllabus: Database Management System Lab Code: CS691 Contact: 3P Credits: 2 Structured Query Language 1. Creating Database Creating a Database Creating a Table Specifying Relational Data Types Specifying Constraints Creating Indexes 2. Table and Record Handling 1. INSERT statement 2. Using SELECT and INSERT together 3. DELETE, UPDATE, TRUNCATE statements 4. DROP, ALTER statements 3. Retrieving Data from a Database The SELECT statement Using the WHERE clause Using Logical Operators in the WHERE clause Using IN, BETWEEN, LIKE , ORDER BY, GROUP BY and HAVING Clause Using Aggregate Functions Combining Tables Using JOINS Subqueries 4. Database Management Creating Views Creating Column Aliases Creating Database Users Using GRANT and REVOKE

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class 1Covers overview of tables and assignment of first day.

Data

What is data ?

What is quantitative and qualitative data ?

What is metadata ?

What is structured data , unstructured data ?

<?xml version="1.0"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book>

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

SQL

SQL

DDL DML

Select Insert Update Delete

DCL TCL

select * from test;

insert into test values (4,200,'string values')

select temp from test

update test set temp='dummy text' where

temp is nulldelete from test where id = 3

Grant , Revoke

Set transaction , commit , rollback

Table

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Create Table

Create Table <Tablename>

{

<column name> <datatype> <constraints>,

……….

}

Simple Form :

SQL> create table test

( id integer,

name varchar2(50)

);

Create Table

Adding constraints

SQL> create table test1

(

id integer not null,

age integer default 25,

name varchar2(50)

);

Other options

We can add a primary key ( There are 5 type of constraint – Primary Key,

Foreign Key, Not Null, Unique and Check )

We can use ENCRYPT clause

We can give option as GENERATED ALWAYS AS

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Primary Key, Foreign Key constraint

create table empl

(

id integer primary key,

age integer default 25,

name varchar2(50)

);

create table dpndnt

(

id integer primary key,

age integer default 25,

name varchar2(50) ,

eid integer not null CONSTRAINT dpndnt_fkey REFERENCES empl(id)

);

A primary key value cannot be null

All primary key values must be unique within a

column

Primary key values can optionally be paired with

a corresponding foreign key value in another table,

forming a relationship

it can be mentioned as inline or as a constraint

at the end

Altering a tableModifying a datatype

Alter table test1

Modify name varchar2(100);

Adding a Column

Alter table test1

Add extra char(10);

Dropping a Column

Alter table test1

Drop column extra char(10);

Adding or changing constraint

alter table empl

modify name not null;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Metadata, data dictionary

desc <tablename> ;

user_tables - > Gives details about the tables

User_tab_columns -> Gives details about the columns

Assignment

- Complete schema design for a student attendance system

- It should have entity for class , student , subject , routine , attendance

- Create proper primary key and foreign keys

- Write notes on Temporary table and Global Temporary table

- Give an example where CATS will be necessary , with necessary syntax

- Give a listing of the tables , columns and constraints

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class I1Overview of select , insert , update , delete

Contains class II assignments

SELECT

SELECT

[DISTINCT | UNIQUE] (*, columnname [ AS alias], …)

FROM

tablename

[WHERE condition]

[GROUP BY group_by_expression]

[HAVING group_condition]

[ORDER BY columnname];

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Select Contd …

Selecting all columns using *

Selecting some of the columns -> Projection

Alias names if contains space or special symbol , then it needs to be put in

double quotes

Distinct and unique can be used to remove duplicates

comparison operators =; != or <>; <; >;<=, => are allowed in the

conditions of a where clause.

One useful query to get the number of queries is count(*)

Order by , by default gives result in ascending order

For string type of data like can be used.

| | is used as a concatenation operator for strings and string literal is to be

enclosed within single quotes.

Select Contd …

Multiple conditions can be concatenated using and or etc

for range queries we can use between and .

Example : Select emailto, email from email where size between 10 and 20;

IN for multiple values

Select city, population from citydetails where city in (‘kol’,’mum’,’del’,’chn’);

Similarly not in can be used

Like to be used for pattern matching ‘a%’, ‘%a%’ and ‘%a’

An input value can be taken form the user , using and &

select * from dept where deptno=&no;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Select Contd …

Multiple conditions can be concatenated using and or etc

for range queries we can use between and .

Example : Select emailto, email from email where size between 10 and 20;

IN for multiple values

Select city, population from citydetails where city in (‘kol’,’mum’,’del’,’chn’);

Similarly not in can be used

Like to be used for pattern matching ‘a%’, ‘%a%’ and ‘%a’

An input value can be taken form the user , using and &

select * from dept where deptno=&no;

Case sensitivity, whitespace,

terminators SQL commands have the same meaning whether used with uppercase or

lowercase characters

various SQL elements, or "words", must be separated by whitespace

(usually a "space" character), the use of extra spaces, tabs, and end-of-line

character has little effect on the syntactical correctness of the statement.

In Oracle SQL, two statement terminators can be used; the semicolon (;)

and the forward slash (/). The two are similar in their use, the main

difference being that the forward slash can only be used on a separate line.

Aliasing:

select dname as "Departmentname" , loc as "Location" from dept;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Assignments

write query to select all the columns of emp table

write query to select only Empname, Ename and Job

write query to select unique Jobs

write query to select only those employees who are salesman

select employee name , grade and salary , in the order of their salary

Mgmt is considering a pay raise , however they want to find out , if they

give a flat 200$ increment to all , then what % each person is getting . So in

your result display , ename , salary and pctincr

Express work experience of each of the employeses by using sysdate and

hiredate in terms of no of years.

Hints : you would need to use cast

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Assignments contd.

select only those employees who are a clerk and a manager. Use all of ‘or’

condition , ‘IN’ and ‘NOT IN’ clause

Comment on the case sensitivity of the string literal within single quote

use emp table and use different columns and string concatenation to

display a message like below for each of the employees

Output Example :

JAMES is a CLERK and is working in the company for last 32 Years

use emp table to display only those employees who have joined in the year

80 and 81.

Comment on if between clause is inclusive or exclusive

Assignments contd. Use like statement to display name of the employees which start with

‘A’

Write your remarks on use of wildcards with like statement

Select those employees , who has joined on or before 31st December

1982 and is either a clerk or having a salary greater than 2500

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class IIIGroup by , Having

Insert/Update/Delete

System Functions

Set Operators

Group By

Select <column(s)>

from <table(s)>

[where <condition>]

group by <group column(s)>

[having <group condition(s)>];

The result will return # rows based in the group columns, basically based

on distinct combination of group by columns

Some aggregate functions needs to be used on the columns.

Example : Sum, Avg, Min, Max , count(*) etc

‘Having’ is used to restrict some of the groups appearing in the result

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Insert/Update/Delete

Insert into <table> [(<column i, : : : , column j>)]

values (<value i, : : : , value j>);

For each of the listed columns, a corresponding (matching) value must be

specified.

Insertion does not necessarily have to follow the order of the attributes as

specified in the create table statement

If a column is omitted, the value null is inserted instead

update <table> set

<column i> = <expression i>, : : : , <column j> = <expression j>

[where <condition>];

delete from <table> [where <condition>];

Case conversion ,String

String Functions

• Upper

• Lower

• Initcap

• Length

• Lpad

• Rpad

• Rtrim

• Ltrim

• Concat

• substr

• instr

SUBSTR(column_expression, start position, end position)

INSTR(column_expression, search_character,

starting_position, occurrence_number)

Lpad/Rpad (Column, length,padding column)

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Date functions, conditions

Current _timestamp is a pseudo column like sysdate

Month_between ( Start date, end date )

Add_months ( Date , no of months)

Decode (Column , condition, value, condition, value )

It can be if and else if , else

it can be else

it can be if and else if , in this case for no match null is returned

DECODE(E1, E2, E3, E4) IF E1 = E2 THEN E3 ELSE E4

NULLIF(E1, E2) IF E1 = E2 THEN NULL ELSE E1

NVL(E1, E2) IF E1 IS NULL THEN E2 ELSE E1

NVL2(E1, E2, E3) IF E1 IS NULL THEN E3 ELSE E2

CASE WHEN C1 THEN R1 WHEN C2 THEN R2 . . . WHEN CN THEN RN ELSE RD

END

Set operators

Set operators can be used to combine records from multiple tables

Different operators are union, union all, intersect , minus respectively

Union removes the duplicates , where as union all does not

Both the sets need to have the same no of columns and compatible

datatypes

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class IVJoins

Subquery

Join

A join query extracts information from two or more tables or views. A join

query differs from a regular query in at least the following two ways:

The FROM clause of a join query refers to two or more tables or views.

A condition is specified in the join query (known as join condition) that

relates the rows of one table to the rows of another table.

SELECT

departments.location_id, departments.department_name,

locations.state_province FROM

departments JOIN locations

ON departments.location_id = locations.location_id;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Type of Joins Inner Join : Inner joins are the regular joins. An inner join returns the rows that

satisfy the join condition.

Outer Join : Outer joins are an extension to inner joins. An outer join returns the rows that satisfy the join condition and also the rows from one table for which no corresponding rows (i.e., that satisfy the join condition) exist in the other table.

FROM table1 { LEFT | RIGHT | FULL } [OUTER] JOIN table2

◦ Left Outer join :

◦ Right Outer Join

◦ Full outer Join

Cartesian join or cross join

when you don't specify a join condition when joining two tables

Self joins

A self join is a join of a table to itself.

Equi- and non-equi-joins

An equi-join is a join where the join condition uses the equal to (=) operator to relate the rows of two tables

Other points of join Oracle proprietary syntax is different , inner join is written in table 1,

table 2 where table 1.columnname= table2.columnname.

A + sign is used to indicate an outer join

SELECT FIRSTNAME, LASTNAME, PROJECTNAME

FROM EMPLOYEE E, PROJECT P

WHERE E.PROJECT_ID(+)=P.PROJECT_ID

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Subquery

A subquery is simply a query that is nested inside another query ora nested query

The nested query, sometimes referred to as an inner query, isevaluated first, and its resulting data set is passed back to the outerquery and evaluated to completion.

Subqueries can be effectively used in situations where thecombined data has no direct relationship as compared to joins

scalar or single-row subqueries :The subquery returns a singlevalue to the outer query

Scaler subqueries can be used for both where and having clause.

Subqueries are most often found in the WHERE clause of aSELECT,UPDATE, or DELETE statement

Ex : Select name of the employees other than Kevin Feeney whogets the same salary as Kevin

Non correlated subquery

Noncorrelated subqueries allow each row from the containing SQL

statement to be compared to a set of values.

The nested query, sometimes referred to as an inner query, is

evaluated first, and its resulting data set is passed back to the outer

query and evaluated to completion.

Subqueries can be effectively used in situations where the

combined data has no direct relationship as compared to joins

scalar or single-row subqueries :The subquery returns a single

value to the outer query

Scaler subqueries can be used for both where and having clause.

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Correlated subquery

A correlated subquery is a subquery that uses values from theouter query, requiring the inner query to execute once for eachouter query

With a correlated subquery, the database must run the subqueryfor each evaluation because it is based on the outer query’s data.

select book_key, store_key, quantityfrom sales s

Where quantity <(select max(quantity) from sales where book_key = s.book_key);

SELECT S.Number, S.Name FROM Salesman S

WHERE S.Number IN (SELECT C.Salesman FROM Customer CWHERE C.Name = S.Name)

Non correlated and correlated

subquery – contd. Noncorrelated subqueries allow each row from the containing SQL

statement to be compared to a set of values.

◦ Single-row, single-column subqueries

◦ Multiple-row, single-column subqueries

◦ Multiple-column subqueries

SELECT lname FROM employee WHERE salary > (SELECT AVG(salary) FROM

employee);

SELECT fname, lname FROM employee WHERE dept_id = 30 AND salary >= ALL

(SELECT salary FROM employee WHERE dept_id = 30);

SELECT fname, lname FROM employee WHERE dept_id = 30 AND NOT salary < ANY

(SELECT salary FROM employee WHERE dept_id = 30);

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Assignments

Display name of employees , department name and job name for each

employee

Display the department name along with no of employees and average

salary of that department

For each department , find out no. of jobs the employees are assigned to.

Check for correctness of the above queries in terms of count, if you want

to bring in all entries , how would you achieve the same?

Group by the employees based on the first character of employee first

name. Display the results in alphabetic order (descending) of first character.

Display name of those employees who get a salary more than the average

salary

Display name of the all the employees who are ‘stock manager’ , except

the one who gets the minimum salary .

Assignments contd.

Display firstname,lastname,salary of those sales representatives who earns

a higher salary than the minimum salary a sales manager receives.

Display the name of the employees/employee who gets the second highest

salary. (sub query)

Come up with the query for previous question using set operators

Display the name of the employee (manager) who has the maximum no. of

employees reporting to him.

Display the name of those employees , who are in the same department

as Timothy Gates and gets an salary more than the average salary of all the

employees

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Assignments contd. If an employee have spent less than 5 years then he is considered

entry level id 5 – 10 then midlevel else a senior employee. Write a

query, which will label the employees in either of the above categories

Write query to find out any departments that are present in

department table but does not have employees

Write a query which will display job id , which are present in both job

and employee columns

Increase salary of each employee of all the department who draws

the minimum salary by 100$.

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class VPL/SQL basics

Architecture

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Single Unit

What Is PL/SQL?PL/SQL is a procedural programming language from

Oracle that combines the following elements:

Logical constructs such as IF-THEN-ELSE and WHILE

SQL DML statements, built-in functions, and operators

Transaction control statements such as COMMIT and

ROLLBACK

Cursor control statements

Object and collection manipulation statements

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

A simple PL/SQL block

The Declaration section (optional)

The Declaration section of a PL/SQL Block starts with the reserved keyword DECLARE. This

section is optional and is used to declare any placeholders like variables, constants, records and

cursors

The Execution section (mandatory).

The Execution section of a PL/SQL Block starts with the reserved keyword BEGIN and ends

with END. This is a mandatory section and is the section where the program logic is written to

perform any task. The programmatic constructs like loops, conditional statement and SQL

statements form the part of execution section.

The Exception (or Error) Handling section (optional)

The Exception section of a PL/SQL Block starts with the reserved keyword EXCEPTION. This

section is optional. Any errors in the program can be handled in this section, so that the PL/SQL

Blocks terminates gracefully.

Example - procedureDECLARE

v_sal numeric(7,2);

v_ename varchar(10);

BEGIN

SELECT max(sal)

INTO v_sal

FROM emp;

SELECT ENAME INTO V_ENAME from empWHERE SAL=V_SAL;

DBMS_OUTPUT.PUT_LINE (v_ename||' gets highest salary of ' ||v_sal );

END;

/

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Example - functionCREATE OR REPLACE FUNCTION getmaxval (tnameVARCHAR2 ,

cnameVARCHAR2)

RETURN NUMBER IS

query_strVARCHAR2(1000);

maxval NUMBER;

BEGIN

query_str := 'SELECT max(' || cname || ') FROM ' ||tname;

EXECUTE IMMEDIATE query_str

INTO maxval;

RETURN maxval;

END;

/`

Class Assignment :

Create a function which takes two parameters tablename and

columnname and returns second max value of the columns.

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class VIException Block

Cursors

For Loops

Pl/sql – some more basics

Loop through records, manipulating them one at a time.

Keep code secure by offering encryption, and storing code permanently on the

server rather than the client.

Handle exceptions.

Work with variables, parameters, collections, records, arrays, objects, cursors,

exceptions, BFILEs, etc.

Pl/SQL is first compiled and stored and then interpreted

Reminder : use of ed

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Exception blocks

CREATE OR REPLACE FUNCTION getname (vsal number)

RETURN varchar2 IS

query_strVARCHAR2(1000);

vename varchar2(100);

BEGIN

query_str := 'SELECT ename FROM emp' ||' where sal= ' || vsal;

EXECUTE IMMEDIATE query_str

INTO vename;

query_str := vename || ' gets ' || vsal;

RETURN query_str;

EXCEPTION

WHEN NO_DATA_FOUND THEN

RETURN 'NOT FOUND';

END;

/

Packages

Stored functions and procedures may be compiled individually, or they may be

grouped together into packages.

Packages are loaded into memory as a whole, increasing the likelihood that a

procedure or function will be resident in memory when called.

Packages can include private elements, allowing logic to be hidden from view.

Placing functions and procedures inside packages eliminates the need to

recompile all functions and procedures that reference a newly recompiled

function/procedure.

Function and procedure names may be overloaded within packages, whereas

standalone functions and procedures cannot be overloaded.

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

LoopsDECLARE

v_count PLS_INTEGER := 0;

BEGIN

LOOP

DBMS_OUTPUT.PUT_LINE('Ah -- Much better');

v_count := v_count + 1;

EXIT WHEN v_count = 20;

END LOOP;

END;

/

FOR counter IN low_number .. high_number

LOOP

action;

END LOOP;

WHILE condition

LOOP

action;

END LOOP;

For Loop and DECLARE

i NUMBER := 5;

BEGIN

FOR i IN 1..3 LOOP

DBMS_OUTPUT.PUT_LINE ('Inside loop, i is ' || TO_CHAR(i));

END LOOP;

DBMS_OUTPUT.PUT_LINE ('Outside loop, i is ' || TO_CHAR(i));

END;

/

DECLARE

v_count PLS_INTEGER := 1;

BEGIN

WHILE v_count <= 20

LOOP

DBMS_OUTPUT.PUT_LINE('While loop iteration: '||v_count);

v_count := v_count + 1;

END LOOP;

END;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

CursorA cursor provides a subset of data, defined by a query, retrieved into memorywhen opened, and stored in memory until the cursor is closed.

If data is added, deleted, or modified after the cursor is opened, the new or

changed data is not reflected in the cursor result set.

Declaration of a cursor:

CURSOR author_cur1

IS

SELECT rowid

FROM authors

WHERE id > 50;

Opening a cursor

OPEN author_cur1;

Cursor Contd.Use a cursor in a loop

Opening a loop:

LOOP

Fetch:

FETCH auth_cur INTO v_first_name, v_last_name, v_book_count;

Exit:

EXIT WHEN auth_cur%NOTFOUND;

End Loop

END LOOP;

Close Cursor

CLOSE auth_cur;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Example of a simple cursorCREATE OR REPLACE PROCEDURE compile_warning

AS

v_titleVARCHAR2(100);

CURSOR dbms_warning_cur

IS

SELECT title

FROM books;

BEGIN

OPEN dbms_warning_cur;

LOOP

FETCH dbms_warning_cur INTO v_title;

EXIT WHEN dbms_warning_cur%NOTFOUND;

DBMS_OUTPUT.PUT_LINE('Titles Available: '||v_title);

END LOOP;

CLOSE dbms_warning_cur;

END;

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Oracle Class VIIMore on Execption

Sequence

Triggers

RowID & Rownum

Views

ExceptionDifferentiate error and exception

More example :

EXCEPTION

WHEN ZERO_DIVIDE THEN

DBMS_OUTPUT.PUT_LINE ('A number cannot be divided by zero.');

VALUE_ERROR :- When there is conversion or type mismatch error.

TOO_MANY_ROWS: This exception is raised when a SELECT INTO statement returns

more than one row.

You can declare your own exception

DECLARE

e_exception1 EXCEPTION;

BEGIN

RAISE e_exception1

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

SequenceAn Oracle sequence is an Oracle database object that can be used to generate unique

numbers. You can use sequences to automatically generate primary key values.

After a sequence has been created, you can access its values in SQL statements with these

pseudocolumns:

. CURRVAL returns the current value of the sequence.

. NEXTVAL increments the sequence and returns the new value

We can use a maxvalue or minvalue to indicate the maximum value a trigger can

have

CYCLE is used to indicate , if maxvalue is reached , then the values will be cycled

(NOCYCLE by default)

Example of sequence:

CREATE SEQUENCE trig_seq START WITH 1;

CREATE SEQUENCE trig_seq1 START WITH 1 INCREMENT BY 1;

CREATE SEQUENCE trig_seq2 START WITH 1 INCREMENT BY 1 maxvalue 255;

Example of using a sequence:

INSERT INTO test01 VALUES (trig_seq.NEXTVAL);

Triggers

A database trigger is a named PL/SQL block stored in a database and executed

implicitly when a triggering event occurs. The act of executing a trigger is called firing

the trigger.

Four types of triggering events :-

A DML statement (such as INSERT, UPDATE, or DELETE) executed against

a database table. Such a trigger can fire before or after a triggering event.

A DDL statement (such as CREATE or ALTER) executed either by a

particular user against a schema or by any user.

A system event such as startup or shutdown of the database.

A user event such as logon and logoff

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

Trigger continued

CREATE [OR REPLACE] TRIGGER Ttrigger_name

{BEFORE|AFTER} Triggering_event ON table_name

[FOR EACH ROW]

[FOLLOWS another_trigger]

CREATE OR REPLACE TRIGGER student_bi

BEFORE INSERT ON students

FOR EACH ROW

DECLARE

sid int;

BEGIN

select max(stid)+1 into sid from students;

dbms_output.put_line('hello');

:new.stid:=sid;

END;

/

FOR EACH ROW

WHEN (NVL(NEW.ZIP, ' ') <> OLD.ZIP)

RowId & Rownum

For each row in the database, the ROWID pseudocolumn returns the address

of the row.

Use of Rowid:

They are the fastest way to access a single row.

They can show you how the rows in a table are stored.

They are unique identifiers for rows in a table.

For each row returned by a query, the ROWNUM pseudocolumn returns a

number indicating the order in which Oracle selects the row from a table or

set of joined rows. The first row selected has a ROWNUM of 1, the second

has 2, and so on.

D a t a b a s e M a n a g e m e n t S y s t e m L a b |

ViewsUse the CREATEVIEW statement to define a view, which is a logical table based on one or more tables or views. A view contains no data itself. The tables upon which a view is based are called base tables.

create view emp10 As select * from emp where deptno=10;

View can be created using join on multiple table

create view empbonus

(ename,sal,job,comm,deptno)

as select a.ename,a.sal,a.job,b.comm, a.deptno from

emp a inner join bonus b on a.ename=b.ename

/

AssignmentsModify the procedure that takes salary and returns the name , handle the

exception so that if user gives a nonnumeric value this exits gracefully.

Create a table books, which has columns as bookid and bookname . Insert

two rows with booknames ‘database fundamentals’ and ‘database

technologies’. Use a sequence to populate the bookid for both the rows.

There is a circular from federal govt. no employees can get salary less than

1000$ . So in case some employees are being inserted in the table with salary

less than 1000 automatically this should be updated to 1000, Write a trigger

for the same. Do it first by a just changing the below in insert before , and

also by an update command after insert is done.

Create a trigger on emp table such that when a new employee is inserted

with a deptno that is new , first insert that record in department and then

insert the same in emp to avoid foreign key error.

Create a view , which hides the salary column from the user.

Cerate a view which has ename and dname respectively , check if you can

update/insert into the views , justify your results

D a t a b a s e M a n a g e m e n t S y s t e m L a b |