VIEWS IN SQL WITH EXAMPLES | WHY VIEWS ARE USED?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to my channel and in this video we are going to see we use and as SQL so what I've used views are basically virtual table now what should means they do not exist in reality it is just a virtual table okay now by selecting fields from one or more tables present in dB so how have you is created we are going to select fields see is basically columns from one or more tables present in DB and can have conditions also so we can have there so this is the basic syntax for views create view whatever name you want to give as select whatever columns you want to select from whichever table where whatever condition you have okay so view is our virtual tables now let's see two examples now now view when you view using a single table create view we are going to give it name give a name to the view so the new name is details get create view details as select name and address from students so students in the table name so we are going to select name and address from students where ID is lesson one minute we can have any condition over your we can also have all the backbone all of that we can have anything in a view any query okay now multiple tables now how to create a view when we have multiple tables create view details as select s dot name s dot address m dot mass from students as marks and whereas the ride is good am ready so when you are selecting one or two tables or more than that you need to give some allies or you can simply write a where students dot name marks out now something like that or you can use allies okay SRM so so they are going to select s dot name - so s is what student so from the students table it is going to select name address and from the marks table it is going to select marks where is the ride is good m'lord ID okay now if you want to drop of you drop of you you have to simply write drop view whatever the name of the drop is now let's see what are the benefits of you viewers okay now why do we use views right why can't we create just another table and all of that right so what are the benefits views can hide complexity now in case you want to join join two tables and there is a lot of complexity you can use a view and it will reduce the complexity because the view can be suppose you create a view with some other tables and this and then you can join this table with another table another existing table and you can join and you can print the values imagine when when there is no view you have to you have to join three four tables together it can be very complex hence view scale hide complexity now the second benefit which is a major benefit of use and by exactly it is used views can be used as a security mechanism for example we have a big table of employees or customers or some big tip pivot table for example customers okay and that table has a lot of columns it has name address credit card details address and a lot of details but when you create a view you can hide some columns if you want to if you don't want a user to see all the values in the table all the way if you don't want the user to see the values of values for the credit card number for all the all the different customers in the table you can use views in views you can restrict the columns which a person can see or not right when I right away or select s dot name as or address I am restricting the user to only see name and address they cannot see anything else they cannot see anything else in the in the main table so this is my views are used for security mechanism okay and hope this is clear and there are two points to note there is no record in the view it only holds a definition of table and fetches the data from the table and shows it so what this means is when you create a view it is not a venue plate of view you will think it is a table it is a table that will have rows and it will have all the values in it no it will not have values in the table it is just a query the user store as permanent very objects in data dB so then ever you select a view or you use a view it will query it and then it will give you the values give you the Rose it is not stored in the DB though the rows of the views are not stored in the DB it is stored as a query object the query is query is run every time so it only holds a definition of table it will not hold the records in the table I hope that is also clear so I hope what
Info
Channel: Crack Concepts
Views: 75,157
Rating: 4.7724004 out of 5
Keywords: Views in sql, Views in sql with examples, Creating views on sql
Id: zUj1dH4IFPI
Channel Id: undefined
Length: 5min 13sec (313 seconds)
Published: Sat May 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.