Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 drop user in serveral databases - usp?

Author  Topic 

EA
Starting Member

19 Posts

Posted - 2007-05-01 : 10:54:26
I want to drop users in several databases (but not all!). In pseudo code it's like:

use database1

go

if exists (select name from sys.database_principals where upper(name) = 'name1todrop')
drop user name1todrop

go

if exists (select name from sys.database_principals where upper(name) = 'name2todrop')
drop user name2todrop

go

use database 2

go

if exists (select name from sys.database_principals where upper(name) = 'name1todrop')
drop user name1todrop

go

.

.

This is working fine. But now I want to make a stored procedure out of it.

I can't use the 'use database' (a USE database statement is not allowed in a procedure, function or trigger.)

The drop user only works for the current database. But how to make it current in a stored procedure? The databasename is not allowed in the syntax....



Any help or suggestions are welcome!
   

- Advertisement -