Link to home
Start Free TrialLog in
Avatar of 25112
25112

asked on

keep only certain schema tables from a restore

there are 10 schemas in a backup file.. after the restore, though, we want to only the tables from 2 schemas..

after restore, what could be a simple script to drop all the tables that dont belong to those 2 (LTW & PTO) schemas?



thanks
Avatar of lcohan
lcohan
Flag of Canada image

You could build some dynamic code to get all tables not in schema like


--find all tables in schema
select so.name --*
from  sys.objects so inner join sys.schemas ss on so.schema_id = ss.schema_id
where ss.name not in('LTW','PTO')
      and so.type = 'U' -- user table
      

then loop trhough the set and create/execute a DROP TABLE command.
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial