Register   |   Login   |   February 07, 2012    |   Knowledge Base  >  Knowledge Base Systems  >  MSSQL  >  syntax ro run cmd for each table or db
search:     

Phone: 480-722-1227
Toll Free: 888-722-1227

syntax ro run cmd for each table or db
Last Post 05 Jun 2007 05:52 PM by Chris Muench. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Chris MuenchUser is Offline
New Member
New Member
Posts:57

--
05 Jun 2007 05:51 PM  
This tells of 2 sp's in mssql that let you run sql commands against each table or db in a server.
http://www.databasejournal.com/feat...hp/3441031
Chris MuenchUser is Offline
New Member
New Member
Posts:57

--
05 Jun 2007 05:52 PM  
The following works great for me to run against all the databases on a specific server.
[sql]
declare @cmd1 varchar(500)
declare @cmd3 varchar(500)
set @cmd1 =
'if ''?'' <> ''tempdb'' print ''*** Processing DB ? ***'''
set @cmd3 = 'if ''?'' <> ''tempdb'' dbcc checkdb(?)'
exec sp_MSforeachdb @command1=@cmd1,
@command3=@cmd3
[/sql]
You are not authorized to post a reply.

Active Forums 4.2
Copyright 2006 - 2011 Vigilant Support   |  Privacy Statement  |  Terms Of Use