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
 General SQL Server Forums
 New to SQL Server Programming
 how to execute this script on sql server 2008

Author  Topic 

mavericky
Posting Yak Master

117 Posts

Posted - 2012-02-16 : 15:24:45
Hi,
I want to execute the output of this script at run time:
Select 'ALTER TABLE dbo.' + B.name + ' DROP CONSTRAINT ' + A.name
from (select A.name, A.parent_object_id from sys.all_objects A where A.type='F') A
INNER JOIN (select B.name, B.object_id from sys.all_objects B) B
ON A.parent_object_id = B.object_id

If directly copy, paste the above code and press 'Execute' in SQL Server 2008 it generates alter ..drop statements. But I want all those statements to be executed.
Can anyone help me?

Thanks,
Amol

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-16 : 15:28:48
You are going to want to use a CURSOR to do this

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-16 : 15:34:50
why not copy paste the result onto a different query window and click execute

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -