• It is possible to use sp_MSforeachtable in this context. You just need to strip out all the extraneous characters when you pass the name to the function call. For example, contrast the output from these two statements:

    -- output as [dbo].[tablename]

    exec sp_MSforeachtable 'print ''?'''

    -- output as tablename

    exec sp_MSforeachtable 'print replace(replace(''?'',''[dbo].['',''''),'']'','''')'


    Tony