0% found this document useful (0 votes)
7 views4 pages

Exp 8 Views

The document outlines an experiment to implement SQL views, detailing the aim, objectives, and step-by-step procedure for creating, inserting, deleting, updating, and dropping views. It includes specific SQL commands and examples for each operation on a sample 'EMPLOYEE' table and its corresponding 'EMPVIEW' view. The experiment concludes with successful execution and verification of the SQL commands for views.

Uploaded by

choleacademy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Exp 8 Views

The document outlines an experiment to implement SQL views, detailing the aim, objectives, and step-by-step procedure for creating, inserting, deleting, updating, and dropping views. It includes specific SQL commands and examples for each operation on a sample 'EMPLOYEE' table and its corresponding 'EMPVIEW' view. The experiment concludes with successful execution and verification of the SQL commands for views.

Uploaded by

choleacademy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO: 8 Write SQL statements to implement

VIEWS
AIM
To execute and verify the SQL commands for Views.

OBJECTIVE:
Views Helps to encapsulate complex query and make it reusable.
Provides user security on each view - it depends on your data policy
security.
Using view to convert units - if you have a financial data in US currency,
you can
create view to convert them into Euro for viewing in Euro currency.

PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert attribute values into the table.
STEP 4: Create the view from the above created table.
STEP 5: Execute different Commands and extract information from the View.
STEP 6: Stop

SQL COMMANDS
1. COMMAND NAME: CREATE VIEW
COMMAND DESCRIPTION: CREATE VIEW command is used to define a view.
2. COMMAND NAME: INSERT IN VIEW
COMMAND DESCRIPTION: INSERT command is used to insert a new row into the
view.
3. COMMAND NAME: DELETE IN VIEW
COMMAND DESCRIPTION: DELETE command is used to delete a row from the view.
4. COMMAND NAME: UPDATE OF VIEW
COMMAND DESCRIPTION: UPDATE command is used to change a value in a tuple
without changing all values in the tuple.
5. COMMAND NAME: DROP OF VIEW
COMMAND DESCRIPTION: DROP command is used to drop the view table

COMMANDS EXECUTION
CREATION OF TABLE
--------------------------------
SQL> CREATE TABLE EMPLOYEE (
EMPLOYEE_NAME VARCHAR2(10),
EMPLOYEE_NO NUMBER(8),
DEPT_NAME VARCHAR2(10),
DEPT_NO NUMBER (5), DATE_OF_JOIN DATE);
Table created.

TABLE DESCRIPTION
-------------------------------
SQL> DESC EMPLOYEE;
NAME NULL? TYPE
------------------------------- -------- ------------------------
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DATE_OF_JOIN DATE

SYNTAX FOR CREATION OF VIEW


--------------------------------------------------
SQL> CREATE <VIEW> <VIEW NAME> AS SELECT
<COLUMN_NAME_1>, <COLUMN_NAME_2> FROM <TABLE NAME>;

CREATION OF VIEW
------------------------------
SQL> CREATE VIEW EMPVIEW AS SELECT
EMPLOYEE_NAME,EMPLOYEE_NO,DEPT_NAME,DEPT_NO FROM
EMPLOYEE;
VIEW CREATED.

DESCRIPTION OF VIEW
--------------------------------
SQL> DESC EMPVIEW;
NAME NULL? TYPE
----------------------------------------- -------- ----------------------------
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)

DISPLAY VIEW:
----------------------
SQL> SELECT * FROM EMPVIEW;

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO


---------- ----------- ---------- ----------
RAVI 124 ECE 89
VIJAY 345 CSE 21
RAJ 98 IT 22
GIRI 100 CSE 67

INSERTION INTO VIEW


----------------------------------
INSERT STATEMENT:
SYNTAX:
SQL> INSERT INTO <VIEW_NAME> (COLUMN NAME1,………)
VALUES(VALUE1,….);

SQL> INSERT INTO EMPVIEW VALUES ('SRI', 120,'CSE', 67,'16-NOV-1981');


1 ROW CREATED.
SQL> SELECT * FROM EMPVIEW;

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO


---------- ----------- ---------- ----------
RAVI 124 ECE 89
VIJAY 345 CSE 21
RAJ 98 IT 22
GIRI 100 CSE 67
SRI 120 CSE 67

SQL> SELECT * FROM EMPLOYEE;

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO DATE_OF_J


---------- ----------- ---------- ---------- ---------
RAVI 124 ECE 89 15-JUN-05
VIJAY 345 CSE 21 21-JUN-06
RAJ 98 IT 22 30-SEP-06
GIRI 100 CSE 67 14-NOV-81
SRI 120 CSE 67 16-NOV-81

DELETION OF VIEW:
DELETE STATEMENT:
SYNTAX:
SQL> DELETE <VIEW_NMAE>WHERE <COLUMN NMAE> =’VALUE’;

SQL> DELETE FROM EMPVIEW WHERE EMPLOYEE_NAME='SRI';

1 ROW DELETED.

SQL> SELECT * FROM EMPVIEW;

EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO


---------- ----------- ---------- ----------
RAVI 124 ECE 89
VIJAY 345 CSE 21
RAJ 98 IT 22
GIRI 100 CSE 67

UPDATE STATEMENT:
SYNTAX:
AQL>UPDATE <VIEW_NAME> SET< COLUMN NAME> = <COLUMN NAME>
+<VIEW>
WHERE <COLUMNNAME>=VALUE;

SQL> UPDATE EMPKAVIVIEW SET EMPLOYEE_NAME='KAVI' WHERE


EMPLOYEE_NAME='RAVI';

1 ROW UPDATED.
SQL> SELECT * FROM EMPKAVIVIEW
;
EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO
---------- ----------- ---------- ----------
KAVI 124 ECE 89
VIJAY 345 CSE 21
RAJ 98 IT 22
GIRI 100 CSE 67

DROP A VIEW:
SYNTAX:
SQL> DROP VIEW <VIEW_NAME>

EXAMPLE
SQL>DROP VIEW EMPVIEW;
VIEW DROPED

RESULT: SQL commands for View has been verified and executed successfully.

You might also like