Q:

how to delete only Windows Login in SQL Server

I am using below code to delete SQL Logins
 declare @name  varchar(1000)     
 declare @xtype varchar(20)
 declare @sqlstring nvarchar(4000)

 declare SPViews_cursor cursor for
      SELECT  QUOTENAME(NAME) AS name
     FROM sys.server_principals     

 open SPViews_cursor
 fetch next from SPViews_cursor into @name     

 while @@fetch_status = 0
 begin
    set @sqlstring = 'drop LOGIN ' + @name
    exec sp_executesql @sqlstring
    set @sqlstring = ' '

    fetch next from SPViews_cursor into @name
 end

 close SPViews_cursor
 deallocate SPViews_cursor

but it is dropping all logins, I just need to drop Windows login so only SQL auth. can be possible. Any suggestion? And can this code be made shorter?

A:

Change your query to this:
SELECT  QUOTENAME(NAME) AS name
FROM sys.server_principals
WHERE type = 'U'

U means Window Login. You can find more info here.

