Experiment 5
Experiment 5
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);
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: