Aj is article me ham parhen gen SQL view ke bare me ke “Database/SQL
View” kia hota hay? Iska kia faida
hay? Iska practical use kaha hota hay? Aur isko kese create krte hain?
Database Object:
Views se pehle hamen pata hona chaiye ke “Database Object”
kia hota hay? Database object ko agar ham simply define karen to ye ek object
hota hay jis me ham kuch data ko store krskte hain ya is se data ko refer
krskte hain. Tables, Views, Index, Sequences ye sab database object ki example
hain.
SQL View:
SQL view ek database object hay jo ke ek virtual table hota hay,
Yani physically aisa table database me exists nh krta. Is statement ka matlab
ye hay ke sql view actually ek stored query ka result hota hay jis ko ham bar
bar use krskte hain.
SQL view ki definition yeh hogi ke:
“SQL view ek logical/virtual table hay jo ke ek stored query ka result hota hay.”
“SQL view ek logical/virtual table hay jo ke ek stored query ka result hota hay.”
Ab sawal paida hota hay ke SQL view ki zarorat kaha parskti
hay? Is ko samajhne ke liye ham ek example dekthe hain.
Suppose hamare pas database me do tables hain “Student” ka
aur “Batch” ka. Ab suppose hamen apni application me tamam students ki list
chaiye jis me unke name ho aur unka batch ho, To iske liye ham ek join query
likhen gen jis ki madad se ham ye result obtained krlen gen.
Ab suppose hamen ye kam bar bar krna hay apni application me
to har bar hamen ye join ki complicated query likhni parey gi, Yani ke
developer ke liye muskil hogi ke ye complicated kam bar bar karey aur phir agar
query me changing krni hay to us puri complicated query me hamen changing krni
pari gi jo ke ek acha tarika nhi.
Yahan per SQL view ka behtreen use hay, Q na aisa ho ke ham
is query ka result ko ek hi bar get krlen aur sirf ek choti se statement se us
complicated join query ka result obtain krlen?
To iske liye ham ek view create karen gen, Ye view ek virtual
table hoga jo is query ka result store kare ga, Lekin actual me database me is
tarah ka koi table nh hoga.
SQL view create krne ke liye ham simply jis tarah ek table
create krte hain usi tarah view create karten hain just create ke bad VIEW ka
keyword use krte hain, Example dekhen:
1. CREATE VIEW stdDetail AS
2. SELECT * FROM student s JOIN batch b on s.bid=b.id
Ab SQL view kisi query ka result store kare ga to “AS” ke
bad hamne query likhi jis ka result hamen view me chaiye.
Ek khas bat aur hay view me ke jese hi actual table me koi
changing hogi to view me bhi automatically changes hojaen gen. Yani har bar jab
ham view ko query krte hain to hamare pas latest data hi ata hay.
Ab suppose hamen application me yehi result chaiye ke
students ke name aur unke batch, To ab ki bar ham complicated join query nh
likhen gen, Q ke us ka result hamne pehle hi view me store karadia hay, Isliye
ham simply us view se result ko retrieve kraren gen aur us ke liye simple
select statement likhe gen kuch is tarah
1. SELECT * stdDetail
To ab ek developer ke liye kitni asani hogi, Bajae complex
query likhne ke wo simple select statement likhe ga.
Advantages of SQL View:
SQL View ke advantages ka apko andaza hogya hoga phir bhi
kuch advantages ke list iski yeh hay.
1-Views ki madad se ham complex queries ko simplified krskte
hain.
2-Hoskta hay ke ham chahte hain ke developer security
reasons ki waja se actual table ko access na krpae, Lekin phir bhi us ke data
ko access krskta ho, To wahan per ham SQL view ka use krskte hain.
3-Is tarah view me ham aggregated values store krskte hain
jese suppose upper wali example me agar ham dekhen hay ke har batch me kitne
student hay to uske query likh kr result ko view me store krskte hain.
4-Isi tarah suppose kabhi aisa hua ke hamen DB tables wagera
me koi changing krni par jae like columns ke name ya etc change krne par jae,
Ab agar hamne SQL view use nh kiye honge to hamen application me har jaga
changing krni parey gi jahan jahan hamne us table ko query kia hoga. On the
other hand agar hamne SQL view use kiye honge to hamen sirf view ki query me
changing krni pare gi aur application me sab jaga changes reflect hojae gen.
Isi tarah SQL view ke bohat se advantages hain, Behter hay
view ko sirf tables se data retrieve krne ke liye use kia jae. Update, insertion,
deletion ke features although kuch RDMBS provide krte hain jese MySQL lekin behter
yeh hay ke SQL view ke zariye ye operations perform nh kiye jae.
I hope apko idea hogya hoga ke “Database/SQL View” ka
kitna zabardast use krke ham database se record ko easily retrieve krskte hain.
Don’t forget to share this article to your coding community,
As Sharing is Caring!
No comments:
Post a Comment