**********************************************************
DECLARE DropSchema CURSOR
READ_ONLY
FOR select name from master..sysdatabases where name like 'Some user naming convention%' or name = 'master' or name = 'Tempdb'
DECLARE @DB varchar(40),
@SchemaName varchar(40)
OPEN DropSchema
set @SchemaName = 'user to be dropped'
FETCH NEXT FROM DropSchema INTO @DB
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
declare @str varchar(200)
set @str = 'use ' + @DB + ' Drop Schema ' + @SchemaName
print ''
print ('Dropping Schema ' + @SchemaName + 'From ' + @DB )
Print '==================================================='
print ''
print 'Schema ' + @SchemaName + ' has been dropped or does not exist'
print ''
exec(@str)
END
FETCH NEXT FROM DropSchema INTO @DB
END
CLOSE DropSchema
DEALLOCATE DropSchema
No comments:
Post a Comment