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

Experiment 5

This document outlines the procedure to execute and verify SQL commands for creating and managing views and indexes. It includes steps for creating tables, inserting data, creating views from single and multiple tables, and deleting views. The document also provides SQL syntax and examples for each operation related to views.

Uploaded by

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

Experiment 5

This document outlines the procedure to execute and verify SQL commands for creating and managing views and indexes. It includes steps for creating tables, inserting data, creating views from single and multiple tables, and deleting views. The document also provides SQL syntax and examples for each operation related to views.

Uploaded by

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

EX.

NO:5 VIEWS
DATE:19.3.24
AIM:
To execute and verify the SQL commands for Views and Index.

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

SQL COMMANDS:
VIEWS:
• In SQL, a view is a virtual table based on the result-set of an SQL statement.
• A view contains rows and columns, just like a real table.
• The fields in a view are fields from one or more real tables in the database.
• You can add SQL statements and functions to a view and present the data as if the data were
coming from one single table.
• A view is created with the CREATE VIEW statement.

CREATING VIEWS:
SYNTAX:
CREATE VIEW view_name AS SELECT column1, column2,... FROM table_name WHERE condition;
DESCRIPTION:
This command is used to display the details based on condition.
COMMAND:
SQL> CREATE TABLE Student_Detail(STU_ID INT , NAME VARCHAR(10), ADDRESS
VARCHAR(10));
SQL> INSERT INTO Student_Detail VALUES(1 , 'Stephan' , 'Delhi');
SQL> INSERT INTO Student_Detail VALUES(2 , 'Kathrin' , 'Noida');
SQL> INSERT INTO Student_Detail VALUES(3 , 'DAVID' , 'Ghaziabad');
SQL> INSERT INTO Student_Detail VALUES(4 , 'Alina' , 'Gurugram');
SQL> CREATE TABLE Student_Marks(STU_ID INT , NAME VARCHAR(10), MARKS INT , AGE
INT);
SQL> INSERT INTO Student_Marks VALUES(1, 'Stephan' , 97 , 19);
SQL> INSERT INTO Student_Marks VALUES(2, 'Kathrin' , 86 , 21);
SQL> INSERT INTO Student_Marks VALUES(3, 'DAVID' , 74 , 18);
SQL> INSERT INTO Student_Marks VALUES(4, 'Alina' , 90 , 20);
SQL> INSERT INTO Student_Marks VALUES(5, 'John' , 96 , 18);

VIEWING SINGLE ROW OF TABLE:


SQL> CREATE VIEW DetailsView AS SELECT NAME, ADDRESS FROM Student_Detail WHERE
STU_ID < 4;
SQL> SELECT * FROM DetailsView;

CREATING VIEW FROM MULTIPLE TABLES:


SQL> CREATE VIEW MarksView AS SELECT Student_Detail.NAME,Student_Detail.ADDRESS,
STUDENT_Marks.MARKS FROM Student_Detail,Student_Marks WHERE
Student_Detail.NAME=Student_Marks.NAME;
SQL> SELECT * FROM MarksView;

DELETING VIEW:
SYNTAX:
DROP VIEW view_name;
DESCRIPTION:
This command is used to delete the details based on condition.
COMMAND:
SQL> DROP VIEW MarksView;
SQL> SELECT * FROM MarksView;

RESULT:

You might also like