Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Is there a painless way to REMOVE Schema Binding

Author  Topic 

tcarnahan
Starting Member

23 Posts

Posted - 2014-08-22 : 12:42:24
I am working in a disposable environment to update a "shrink" script. The script is used to purge "bloat" from the big tables in the Production backup copies we use to refresh instances in our Test environment. The script process involves:

For each selected table (one at a time):
1.Copy the data to be retained to a New table (SELECT * INTO ). These tables are dropped after the process finishes "shrinking" the table.
2.Truncating (vs. deleting records from) the Original table. This is to speed up the process and to prevent bloating the transaction log.
3.Inserting the retained data from the new table into the Original table
4.Dropping the New table

I learned that before I can truncate, I have to work around FKs, Indexes, Constraints, etc. So far I have figured out how to do all of those except SCHEMA BINDING. Our database has a LOTS of views with SCHEMA BINDING.

Question: Is there a way I can remove SCHEMA BINDING from ALL views that reference a selected table without having to:
1.Locate all views with SCHEMA BINDING that refer to a table
2.Script each view to create the view without SCHEMA BINDING
3."shrink" the table
4.Script out all views referring to the table to include SCHEMA BINDING

I am probably asking for the moon, but I thought I would see if anyone else has run into this.

Thanks ahead of time for any help you can provide!

Tom

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-22 : 12:55:23
Use the generate script wizard to generate the script for all views, do a find/replace to remove schema binding and then add the views back (or alter).

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2014-08-22 : 13:58:38
I probably would just script out all views - drop the views - perform the shrink process - then recreate all the views. You are already dropping FK's and constraints and rebuilding them so it shouldn't be too hard to include a drop/recreate of the views.
Go to Top of Page
   

- Advertisement -