Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet226/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   222   223   224   225   226   227   228   229   ...   443
Bog'liq
BookSQL

The 

SCHEMABINDING

 Option

The SCHEMABINDING option is available to views and UDFs; it binds the schema of referenced ob-

jects and columns to the schema of the referencing object. It indicates that referenced objects cannot 

be dropped and that referenced columns cannot be dropped or altered.

For example, alter the USACusts view with the SCHEMABINDING option.

ALTER VIEW Sales.USACusts WITH SCHEMABINDING 

AS 

 

SELECT 



  custid, companyname, contactname, contacttitle, address, 

  city, region, postalcode, country, phone, fax 

FROM Sales.Customers 

WHERE country = N'USA'; 

GO 

Now try to drop the Address column from the Customers table.



ALTER TABLE Sales.Customers DROP COLUMN address;

You get the following error.

Msg 5074, Level 16, State 1, Line 1 

The object 'USACusts' is dependent on column 'address'. 

Msg 4922, Level 16, State 9, Line 1 

ALTER TABLE DROP COLUMN address failed because one or more objects access this column.

Without the SCHEMABINDING option, you would have been allowed to make such a schema 

change, as well as drop the Customers table altogether. This can lead to errors at run time when you 

try to query the view and referenced objects or columns do not exist. If you create the view with the 

SCHEMABINDING option, you can avoid these errors.

To support the SCHEMABINDING option, the object definition must meet a couple of technical 

requirements. The query is not allowed to use * in the SELECT clause; instead, you have to explicitly 

list column names. Also, you must use schema-qualified two-part names when referring to objects. 

Both requirements are actually good practices in general.

As you can imagine, creating your objects with the SCHEMABINDING option is a good practice.




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   222   223   224   225   226   227   228   229   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish