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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Is there a painless way to REMOVE Schema Binding
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

23 Posts

Posted - 08/22/2014 :  12:42:24  Show Profile  Reply with Quote
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!


Edited by - tcarnahan on 08/22/2014 12:46:14

Almighty SQL Goddess

38200 Posts

Posted - 08/22/2014 :  12:55:23  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
Go to Top of Page

Aged Yak Warrior

819 Posts

Posted - 08/22/2014 :  13:58:38  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000