USE [master]
GO
EXEC master.dbo.sp_addlinkedserver
@server = N'連線名稱',
@srvproduct=N'SQLNCLI',
@provider=N'SQLOLEDB',
@datasrc=N'192.168.8.198\SQL2008'
GO
USE [master]
GO
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = N'連線名稱',
@locallogin = NULL ,
@useself = N'False',
@rmtuser = N'資料庫登入帳號',
@rmtpassword = N'資料庫連線密碼'
GO
select sid, loginname, dbname from dbo.syslogins;
CREATE LOGIN [loginname] WITH PASSWORD=N'password',
DEFAULT_DATABASE=[dbname ], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF,
SID = sid
select 'CREATE LOGIN [' + loginname + '] WITH PASSWORD=N''XXX'', DEFAULT_DATABASE=[' + dbname + '], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF,SID =' + master.dbo.fn_varbintohexstr(sid) from dbo.syslogins Where loginname = 'username';