fjtello / SQL-C-sharp

Common programming and coding tips and howtos
0 stars 0 forks source link

SQL Eliminar Linked Server #30

Open fjtello opened 7 years ago

fjtello commented 7 years ago

Declare @srv_name varchar(30)

DECLARE Cursor_Base CURSOR FOR SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0

Open Cursor_Base

FETCH NEXT FROM Cursor_Base INTO @srv_name

WHILE @@FETCH_STATUS = 0 BEGIN PRINT @srv_name

EXEC master.dbo.sp_dropserver @server=@srv_name, @droplogins='droplogins'

FETCH NEXT FROM Cursor_Base
    INTO @srv_name

END

DECLARE @CursorEstado INT SET @CursorEstado = CURSOR_STATUS('global','Cursor_Base')

print ' @CursorEstado: '+ cast(@CursorEstado as varchar(30));

IF (@CursorEstado <> -3 ) BEGIN IF (@CursorEstado <> -1 ) CLOSE Cursor_Base DEALLOCATE Cursor_Base END