0% found this document useful (0 votes)
98 views8 pages

EXP-5 Creation of Views, Synonyms, Sequence

The document describes creating and manipulating views, synonyms, and sequences in a database. It first creates tables to hold employee and department data. It then [1] creates a view on the employee table, performs delete and drop operations on the view. [2] Creates a synonym for another table and updates and drops the synonym. [3] Creates a sequence, uses it to insert records into a new table, selects the data, and drops the sequence. The result confirms the program executed and verified as expected.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
98 views8 pages

EXP-5 Creation of Views, Synonyms, Sequence

The document describes creating and manipulating views, synonyms, and sequences in a database. It first creates tables to hold employee and department data. It then [1] creates a view on the employee table, performs delete and drop operations on the view. [2] Creates a synonym for another table and updates and drops the synonym. [3] Creates a sequence, uses it to insert records into a new table, selects the data, and drops the sequence. The result confirms the program executed and verified as expected.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

EXP-5

Creation of Views, Synonyms, Sequence

AIM:
To create the view,synonyms,sequence and verify the various operations on views,
synonyms,sequence.

ALGORITHM:

STEP 1: Start the DBMS.


STEP 2: Connect to the existing database(DB)
STEP 3: Create the table with its essential attributes.
STEP 4: Insert record values into the table.
STEP 5: Create the view,synonyms and sequence from the above created table.
STEP 6: Display the data presented on the VIEW, SYNONYMS and SEQUENCE.
STEP 7: Perform various operations in VIEW, SYNONYMS and SEQUENCE.
STEP 8: Stop DBMS

CREATION OF TABLE:

CREATE TABLE Emp (Empno INTEGER NOT NULL,Ename TEXT NOT NULL,Job TEXT NOT
NULL,MGR INTEGER,HireDate TEXT NOT NULL,Sal INTEGER NOT NULL,Comm
INTEGER,Deptno INTEGER NOT NULL);

INSERT INTO Emp VALUES(7369,'SMITH','CLERK',7902,'17-DEC-80',800,NULL,20);


INSERT INTO Emp VALUES(7499,'ALLEN','SALESMAN',7698,'20-FEB-81',1600,300,30);
INSERT INTO Emp VALUES(7521,'WARD','SALESMAN',7698,'22-FEB-81',1250,500,30);
INSERT INTO Emp VALUES(7566,'JONES','MANAGER',7839,'02-APR-81',2975,NULL,20);
INSERT INTO Emp VALUES(7654,'MARTIN','SALESMAN',7698,'28-SEP-81',1250,1400,30);
INSERT INTO Emp VALUES(7698,'BLAKE','MANAGER',7839,'01-MAY-81',2850,NULL,30);
INSERT INTO Emp VALUES(7782,'CLARK','MANAGER',7839,'09-JUN-81',2450,NULL,10);
INSERT INTO Emp VALUES(7788,'SCOTT','ANALYST',7566,'19-APR-87',3000,NULL,20);
INSERT INTO Emp VALUES(7839,'KING','PRESIDENT',NULL,'17-NOV-81',5000,NULL,10);
INSERT INTO Emp VALUES(7844,'TURNER','SALESMAN',7698,'08-SEP-81',1500,0,30);
INSERT INTO Emp VALUES(7876,'ADAMS','CLERK',7788,'23-MAY-87',1100,NULL,20);
INSERT INTO Emp VALUES(7900,'JAMES','CLERK',7698,'03-DEC-81',950,NULL,30);
INSERT INTO Emp VALUES(7902,'FORD','ANALYST',7566,'03-DEC-81',3000,NULL,20);
INSERT INTO Emp VALUES(7934,'MILLER','CLERK',7782,'23-JAN-82',1300,NULL,10);
CREATE TABLE Dept(Dpetno INTEGER NOT NULL,Dname TEXT NOT NULL,Loc TEXT NOT
NULL);

INSERT INTO Dept VALUES (10, 'Accounting', 'New York');


INSERT INTO Dept VALUES (20, 'Research', 'Dallas');
INSERT INTO Dept VALUES (30, 'Sales', 'Chicago');
INSERT INTO Dept VALUES (40, 'Operations', 'Boston');

CREATE TABLE Salgrade (Grade INTEGER NOT NULL,LoSal INTEGER NOT NULL,HiSal
INTEGER NOT NULL);

INSERT INTO Salgrade VALUES (1,2001,1200);


INSERT INTO Salgrade VALUES (2,1201,1400);
INSERT INTO Salgrade VALUES (3,1401,2000);
INSERT INTO Salgrade VALUES (4,2001,3000);
a. VIEW:
CREATION OF VIEW:

CREATE VIEW Empview AS SELECT Empno, Ename, HireDate FROM Emp;

SELECT* FROM Empview;

OUTPUT:

Empno Ename HireDate

7369 SMITH 17-DEC-80

7499 ALLEN 20-FEB-81

7521 WARD 22-FEB-81

7566 JONES 02-APR-81

7654 MARTIN 28-SEP-81

7698 BLAKE 01-MAY-81

7782 CLARK 09-JUN-81

7788 SCOTT 19-APR-87

7839 KING 17-NOV-81

7844 TURNER 08-SEP-81

7876 ADAMS 23-MAY-87

7900 JAMES 03-DEC-81

7902 FORD 03-DEC-81

7934 MILLER 23-JAN-82


DELETE:

DELETE Empview WHERE Ename =’WARD’;

SELECT *FROM Empview;

OUTPUT:

Empno Ename HireDate

7369 SMITH 17-DEC-80

7499 ALLEN 20-FEB-81

7566 JONES 02-APR-81

7654 MARTIN 28-SEP-81

7698 BLAKE 01-MAY-81

7782 CLARK 09-JUN-81

7788 SCOTT 19-APR-87

7839 KING 17-NOV-81

7844 TURNER 08-SEP-81

7876 ADAMS 23-MAY-87

7900 JAMES 03-DEC-81

7902 FORD 03-DEC-81

7934 MILLER 23-JAN-82


Drop:
DROP VIEW Empview;
view dropped

OUTPUT:
The view Empview has been dropped

b. SYNONYMS

CREATE THE SYNONYM FROM TABLE:

CREATE SYNONYM EMP_SYNONYM FOR Salgrade;

SELECT Grade,HiSal from EMP_SYNONYM;

OUTPUT:

Grade HiSal

1 1200

2 3000

3 2000

4 1400

UPDATE:

UPDATE EMP_SYNONYM SET HiSal=2000 WHERE Grade=1;

SELECT * FROM EMP_SYNONYM;

OUTPUT:
Grade HiSal

1 2000

2 3000

3 2000

4 1400

DROP:

DROP SYNONYM EMP_SYNONYM;

OUTPUT:

The synonym EMP_SYNONYM has been dropped.

c .SEQUENCE

CREATE SEQUENCE:

CREATE SEQUENCE seq1

INCREMENT BY 1

START with 1

MAX VALUE 5

MIN VALUE 0;

CREATE TABLE:
CREATE TABLE Emp2(ID INTEGER NOT NULL,ENAME TEXT NOT NULL,SALARY INTEGER
NOT NULL);

INSERT INTO Emp2 values(seq1.nextval,”HAWKEYE”,30000);

INSERT INTO Emp values(seq1.nextval,”IRONMAN”,50000);

INSERT INTO Emp values(seq1.nextval,”THOR”,60000);

SELECT*FROM Emp2;

OUTPUT:

ID ENAME SALARY

1 HAWKEYE 30000

2 IRONMAN 50000

3 THOR 60000

DROP:

DROP SEQUENCE seq1;

OUTPUT:

The sequence seq1 has been dropped.

RESULT:

Thus the above program has been executed and verified successfully.

You might also like