Conditional sp_MSforeachtable not working

  • I am trying to use the following script to move all tables from the s016PASP schema to dbo schema. So far it doesnt do anything and I can't see why. Can someone take a look and assist?

    exec sp_MSforeachtable '

    IF EXISTS(select * from information_schema.tables where TABLE_SCHEMA = ''s016PASP'' and Table_Name = ''?'')

    BEGIN

    ALTER SCHEMA dbo TRANSFER ?

    END'

  • I figured it out:

    exec sp_MSforeachtable '

    IF EXISTS(select * from information_schema.tables where TABLE_SCHEMA = ''s016PASP'' AND TABLE_NAME = parsename ("?", 1)

    )

    BEGIN

    ALTER SCHEMA dbo TRANSFER ?

    END'

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply