@rmiao - you seem to have contradicted yourself:


@bhosalenarayan, all you need to do is build a wrapper using sp_msforeachdb around your sp_msforeachtable script.

You didn't mention the original script that fails, only your cursor script which was incorrectly prescribed.