views:

459

answers:

2

How can I drop user from a database without dropping it's logging?

The script should check if the user exists in database, if does then drop the user.

+1  A: 

You should probably just have a Dropped/Deleted flag on the user table that you set, thus maintaining referential integrity if you want to keep the logging information for that user.

Otherwise, it sounds like you would have to remove a foreign key constraint that is preventing the delete currently, however I wouldn't recommend this.

jamesaharvey
+1  A: 

Is this what you are trying to do??

IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N'username')
DROP USER [username]

If you are using SQL Server Management Studio you can browse to the user and right-click selecting delete.

doug_w