March 29, 2010 at 10:47 am
I deleted the database, but now have 100+ logins left on the SQL Server. Is there some kind of script I can run, that deletes them all ? I dont want to do one by one.
Thank you
March 29, 2010 at 11:55 am
you would want to write a cursor or any row operator that will loop through sysxlogins, generating a syntax using sp_droplogin, and then executing them either separately or in the script itself
March 29, 2010 at 12:18 pm
..thank you for the tip..I've done an exhaustive search on the Internet for this type of script, but have not found an example...I would think that this type of script is very common among the SQL community...do you have any idea where I could find an example ?
March 29, 2010 at 1:00 pm
March 29, 2010 at 3:01 pm
presuming this is SQL2005 the above will not work in SQL2005.
As this is a one off exercise you can reverse engineer the SQL and run the results -- AFTER EDITING OUT IDS INSTALLED BY SQL
select 'drop login ['+name+']' from master.sys.server_principals
where type in ('S','G','U')
and name != 'sa'
--and default_database_name = 'yourdb'
uncomment the dafault db if you can use that to refine the drop.
Interestingly there seems no obvious way to eliminate the SQL2005 installed accounts and builtin/admin if it is there, even sp_help_revlogin includes these.
so as I say go through the results before running it.
---------------------------------------------------------------------
March 29, 2010 at 3:13 pm
Was there only one database on the server?
I would be careful about removing the logins. George and Ron provide some nice scripts. I would not execute the code from either of them until you have verified that the account does not belong to a different database other than the one you dusted.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 30, 2010 at 6:39 am
Apologies Ron, reading my post back I realise it sounds a bit brusque, which I did not intend.
I should have just said my code was SQL2005 compatible.
---------------------------------------------------------------------
March 30, 2010 at 8:50 am
george sibbald
No apologies necessary ... no offense taken .... you ARE correct my posted code would NOT work in SQL 2005.
Thanks for pointing out that fact.
Who knows how many others might read this forum and go off attempting to use what I had posted and then wondering why it did not work.
You did the community a good turn.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply