Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I want to delete all user of a specify database.
I have query: "SELECT * FROM sys.database_principals ",
this query return all user of ALL database, how can i get only user in specify to delete.
Thanks.
Posted

SQL
----don't use where clause it'll delete all data from receptive table----

BEGIN TRAN
USE [YOUR_DATABASE_NAME] --YOU GIVE DATABASE NAME FROM WHERE YOU WANT TO DELETE
Delete FROM YOUR_TABLE_NAME
--ROLLBACK
--COMMIT
 
Share this answer
 
v2
Comments
NguyenVanDuc 10-Oct-13 1:31am    
Delete FROM sys.database_principals --> it'll delete all user of all database, i want to setup where clause to delete users of ONE database.
MuhammadUSman1 10-Oct-13 1:40am    
know check i updated solution.
NguyenVanDuc 10-Oct-13 4:47am    
BEGIN TRAN
USE [YOUR_DATABASE_NAME] --YOU GIVE DATABASE NAME FROM WHERE YOU WANT TO DELETE
Delete FROM YOUR_TABLE_NAME
--> it'll delete user of "YOUR_TABLE_NAME", not user login of database.
You can see users of database in Object Explorer in Microsoft SqlServer(Database --> Security-->Users)
VICK 10-Oct-13 2:49am    
just truncate the specific user table of that specific DB..
You want the Drop User TSQL statement. Read about it here: http://technet.microsoft.com/en-us/library/ms189438.aspx[^]
 
Share this answer
 
Comments
NguyenVanDuc 10-Oct-13 1:07am    
Thanks for your support,
This is query delete ONLY one user which we have NAME.
I want delete ALL user of ONE database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900