Home > Mobile >  Delete all Users in database
Delete all Users in database

Time:09-02

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%'

enter image description here

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);
  • Related