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.
| Author |
Topic |
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-07-23 : 02:47:18
|
| Hi i have a script and i want to include it in Sp_Msforeachdb on run on each and every Database in My System so is there any way to get include that in this.. as i tried a lots but am not able to do so.or is there any other way to do this...Here is the script which i want to run for all the Databases..select 'ALTER TABLE '+OBJECT_NAME(f.parent_object_id)+ ' ADD CONSTRAINT' + f.name + ' FOREIGN KEY'+'('+COL_NAME(fc.parent_object_id,fc.parent_column_id)+')'+'REFRENCES '+OBJECT_NAME (f.referenced_object_id)+'('+COL_NAME(fc.referenced_object_id,fc.referenced_column_id)+')' as ScriptsFROM sys.foreign_keys AS fINNER JOIN sys.foreign_key_columns AS fcON f.OBJECT_ID = fc.constraint_object_idThanks..iF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-07-23 : 05:59:53
|
| Still i don't have any way out??iF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2009-07-23 : 06:30:50
|
| Do you want to create a script to Generate Foreign Keys, from all of your database on server ??? |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-07-23 : 06:52:01
|
| Yes i want to generate scripts for foreign keys from all of my Databases so i write that scriptiF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2009-07-23 : 08:10:26
|
| http://connectsql.blogspot.com/2009/07/generate-foreign-key-for-all-databases.html |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-07-23 : 08:28:28
|
| Hey Many Thanks that what i want u saved my day m trying to do from early morning but still i get errors from 'Sp_Msforeachdb' i missed some (') great work Thanks..iF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2009-07-23 : 11:22:25
|
| m happy ... tht ur problem is solved |
 |
|
|
|
|
|