View Statement is the essentially subset of table which are put away sensibly in a database means a view is a virtual table in the database whose substance are characterized by a query. Views Help in Providing Security , As we can limit number of segments/fields you can access from
Suppose you are working on a project and there are lot of events. In the event that you have any sql query and you don’t need to store query in any content file or PHP, you make a view Statement and store in mysql.
Create View Syntax
Suppose i have a table in my database named “users”. So now i will create a view for users table.
// this is view statement to select all users table data
CREATE VIEW get_all_users AS SELECT * FROM `users`
// we can also create view with where condition
CREATE VIEW get_user_details AS SELECT * FROM `users` WHERE `user_id` =1
// we can also create view with order by and limit conditions
CREATE VIEW get_users AS SELECT * FROM `users` ORDER BY (ASC OR DESC) LIMIT 0,10
They are comparable to query with the exception of the way that the yield segments can be additionally utilized in queries. So its a sort of settled query thought.
The Purpose of Views Statement are To decrease code intricacy and take the advantage of Code Re-ease of use .
Basically If we are having complex questions with joins and so on you can make and put in view and utilize that view where need of reusing it.
Keep in mind views Statement are not for execution reason these are for keeping up code manageable.
To the database user, the view seems simply like a genuine table, with an arrangement of named sections and columns of information.
SQL makes the fantasy of the view by giving the view a name like a table name and putting away the meaning of the view in the database.
View Statements are utilized for security reason in databases,views confines the user from viewing certain section and lines implies by utilizing view we can apply the limitation on getting to the specific lines and segments for explicit user.
Views show just those information which are referenced in the query, so it indicates just information which is returned by the query that is characterized at the season of production of the View.