블로그 이미지
LifeisSimple

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2010. 11. 23. 02:06 Brain Trainning/DataBase

use master

go

 

 

declare @srvName varchar(100)

 

declare curSrv cursor fast_forward for

                  SELECT

                  srv.name

                  -- ISNULL(ll.remote_name, N'') AS [RemoteUser],

                  -- CAST(ll.uses_self_credential AS bit) AS [Impersonate],

                  -- ll.modify_date AS [DateLastModified]

                  FROM sys.servers AS srv

                                   INNER JOIN sys.linked_logins ll ON ll.server_id=CAST(srv.server_id AS int)

                                   LEFT OUTER JOIN sys.server_principals sp ON ll.local_principal_id = sp.principal_id

                  WHERE ll.remote_name = 'Account_Name'  -- 기타 등등 조건 추가 (원하는 녀석으로)

                  group by srv.name

 

open curSrv

 

fetch next from curSrv

                  into @srvName

                 

while @@FETCH_STATUS = 0

begin

                 

                  EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = @srvName, @locallogin = NULL , @useself = N'False',

                                   @rmtuser = N'NewUser', @rmtpassword = N'NewPassword'

                 

                  fetch next from curSrv

                                   into @srvName

end

 

close curSrv

deallocate curSrv

posted by LifeisSimple