SQL server跨库查询

1,添加映射--这句是映射一个远程数据库
EXEC sp_addlinkedserver ‘远程数据库的IP或主机名‘,N‘SQL Server‘
2,执行登录
--这句是登录远程数据库
EXEC sp_addlinkedsrvlogin ‘远程数据库的IP或主机名‘, ‘false‘, NULL, ‘登录名‘, ‘密码‘3,执行查询:select * from A a join [ip].[数据库].[dbo].[表] b on a.id=b.id 
时间: 2024-08-03 19:24:21

SQL server跨库查询的相关文章

SQL Server跨库访问

MSSQLServer不同服务器数据库之间的数据操作 方法1: --创建链接服务器 exec sp_addlinkedserver   'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址' exec sp_addlinkedsrvlogin  'ITSV ', 'false ',null, '用户名', '密码' --查询示例 select * from ITSV.数据库名.dbo.表名 --导入示例 select * into 表 from ITSV.数据库名.db

SQL Server 跨数据库查询

不同服务器数据库之间的数据操作 --创建链接服务器 exec sp_addlinkedserver   'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '用户名 ', '密码 ' --查询示例 select * from ITSV.数据库名.dbo.表名 --导入示例 select * into 表 from ITSV.数据库名.dbo.表名 --以后不再使用时

SQL Server跨库跨服务器访问实现

我们经常会遇到一个数据库要访问另一个数据库,或者一台服务器要访问另一台服务器里面的数据库. 那么这个如何实现的呢? 相信看完这篇文章你就懂了! 同一台服务器跨库访问实现 1. 首先创建两个数据库CrossLibraryTable1,CrossLibraryTable2 --创建CrossLibraryTable1脚本: use master --打开master数据库,一般的创建语句都在master中执行. go if exists (select * from sysdatabases whe

SQL Server 跨库同步数据

最近有个需求是要跨库进行数据同步,两个数据库分布在两台物理计算机上,自动定期同步可以通过SQL Server代理作业来实现,但是前提是需要编写一个存储过程来实现同步逻辑处理.这里的存储过程用的不是opendatasource,而是用的链接服务器来实现的.存储过程创建在IP1:192.168.0.3服务器上,需要将视图v_custom的客户信息同步到IP2:192.168.0.10服务器上的t_custom表中.逻辑是如果不存在则插入,存在则更新字段. 1 create PROCEDURE [db

sql sever 跨库查询

exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure select * from openrowset( 'SQLOLEDB', '192.168.1.180'; 'sa'; '123.com',joyblessing.dbo.User_Lottery) exec sp_configure 'Ad Hoc Distri

SQL Server跨服务器查询

来源:https://www.cnblogs.com/tylerflyn/p/8339895.html 创建链接服务器 exec sp_addlinkedserver 'ITSV', ' ', 'SQLOLEDB', '远程服务器名或ip地址' exec sp_addlinkedsrvlogin 'ITSV', 'false ',null, '用户名', '密码' --查询示例 select * from ITSV.数据库名.dbo.表名 --导入示例 select * into 表 from

SQL Server 跨库连接

-- 开启组件 exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure -- 关闭组件 exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure

SQL server 跨服务器查询

/*建立连接*/ exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '服务器名称' exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '登录名', '密码' select * from ITSV.表名 /*使用完毕,删除连接*/ exec sp_dropserver 'ITSV ', 'droplogins '

SQL server 跨库插入数据

1.INSERT INTO SELECT语句 语句形式为: Insert into Table2(field1,field2,...) select value1,value2,... from Table1 [where column =value] []为可选内容 要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量. 示例如下: insert into tjjrmx(yybh,xh,tjxmbh,jg,sfyx,zhxmb