I'd like to drop a user in a SQL Server script but I'll need to test for existence first or I'll get script errors. When dropping tables or stored procs, I check the sysobjects table like so:
IF EXISTS (
SELECT *
FROM sysobjects
WHERE id = object_id(N'[dbo].[up_SetMedOptions]')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1
)
Drop Procedure up_SetMedOptions;
GO
What is the corollary for checking for a user? Note that I am NOT asking about a database login to the server! The question pertains to a User in a specific database.
In SQL 2005:
In SQL 2000:
SSMS scripts it in the following way:
For SQL 2005/2008:
For SQL 2000:
The code below worked for me.