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.
该脚本应检查用户是否存在于数据库中,如果是,则删除该用户。
2 个解决方案
#1
39
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.
如果您使用的是SQL Server Management Studio,则可以浏览到该用户并右键单击选择删除。
#2
1
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.
您可能应该在您设置的用户表上放置一个Dropped / Deleted标志,从而在保留该用户的日志记录信息时保持参照完整性。
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.
否则,听起来您必须删除当前阻止删除的外键约束,但我不建议这样做。
#1
39
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.
如果您使用的是SQL Server Management Studio,则可以浏览到该用户并右键单击选择删除。
#2
1
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.
您可能应该在您设置的用户表上放置一个Dropped / Deleted标志,从而在保留该用户的日志记录信息时保持参照完整性。
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.
否则,听起来您必须删除当前阻止删除的外键约束,但我不建议这样做。