A view is a virtual table which is stored in database with an associated name .Using views query we can select specific data from a large table . Suppose there is large database of any college , so i want to view the records of any one branch from that database , this can be done with the views query . view can be create from a single table , multiple table and another view .
Syntax :
select view view_name select column1 , column2 ....columnN from table_name where clause ;
Example :
Table name : Employee_Info
Id Employee_name Employee_Age Employee _Salary City
1 Mukesh 23 120000 Meerut
2 Ayush 24 200000 Baroda
3 Ishan 40 400000 Multan
4 Pranav 35 123,00000 Dehradun
5 Abhishek 26 800000 Mussoorie
6 Ravi 25 300000 Pauri-Garhwal
7 David 40 8000 Baghpat
Query : To create view
create view Employee_view as select Name , Age from Employee_Info ;
Query : Query to retrieve records from Employee_view .
select * from Employee_view
Output :
Employee_name Employee_Age
Mukesh 23
Ayush 24
Ishan 40
Pranav 35
Abhishek 26
Ravi 25
David 40
Query : Query to Update Employee_view .
update Employee_view set age = ' 50 ' where name = ' Ravi ' ;
Output :
Employee_name Employee_Age
Mukesh 23
Ayush 24
Ishan 40
Pranav 35
Abhishek 26
Ravi 50 // row affected
David 40
Query : Query to Drop Employee_view .
drop view Employee_view ;
Output :It delete the Employee_view
Query : Query to Delete row from Employee_view .
delete from Employee_view where age = ' 50 ' ;
Output :Ravi row has been deleted
Employee_name Employee_Age
Mukesh 23
Ayush 24
Ishan 40
Pranav 35
Abhishek 26
David 40
0 Comment(s)