I want to delete all Users after have finished import Bacpac file. So I try Script as below when it said executed successfully but I refresh the database and saw that user still exists. Does anyone have a script or method for solving this case? Thank you for sharing!
USE Catalog
GO
SELECT 'DROP USER [' name '];'
FROM sys.sysusers
WHERE name not in ('guest', 'INFORMATION_SCHEMA', 'sys','public')
and name not like 'db%'
CodePudding user response:
Your query only generates your desired code. It did not execute it.
USE Catalog
GO
DELCARE @Command nvarchar(max) = ''
SELECT @Command = 'DROP USER [' name '];'
FROM sys.sysusers
WHERE name not in ('guest', 'INFORMATION_SCHEMA', 'sys','public')
and name not like 'db%'
EXEC (@Command);