100分 解题思路(迅速结贴) select identity(int,1,1) as id,* into # from (select name, age from tabel1unionselect name, age from tabel2) T 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 scmail81(琳·风の狼) 多谢..但是在不同的计算机里.这样应该不行吧. --同一一个数据库上declare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)insert @table1 values(2,'张三',22)insert @table1 values(3,'李四',20)declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)insert @table2 values(2,'王俊',30)insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from (select name,age from @table1unionselect name,age from @table2) a order by a.age descselect * from #tdrop table #t 现在有两个数据库分别位于两个服务器上,如何实现两者的联合查询?比如查询出库A中的表a和库B中的表b中相同的某字段。该怎么写查询语句?谢谢大家帮忙!--创建链接服务器exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','远程服务器名或ip地址'exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用户名','密码'go --查询示例select * from srv_lnk.A.dbo.a,B.dbo.b where 条件 --同一服务器上,不同的两个数据库declare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)insert @table1 values(2,'张三',22)insert @table1 values(3,'李四',20)declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)insert @table2 values(2,'王俊',30)insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from (select name,age from DataBase1.dbo.@table1 --数据库名.拥有者.表名unionselect name,age from DataBase2.dbo.@table2) a order by a.age descselect * from #tdrop table #t --不同服务器上,不同的两个数据库--创建链接服务器exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','远程服务器名或ip地址'exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用户名','密码'godeclare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)insert @table1 values(2,'张三',22)insert @table1 values(3,'李四',20)declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)insert @table2 values(2,'王俊',30)insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from (select name,age from srv_lnk.DataBase1.dbo.@table1 --数据库名.拥有者.表名unionselect name,age from DataBase2.dbo.@table2) a order by a.age descselect * from #tdrop table #t 如何通过脚本查看作业目前正在执行哪一个步骤 如何得到数据库中所有表的名字 请教!视图上如何增加自动编号的列? 请问如何取得float数的,整数的值及小数部分的值? 数据库总是有几百人访问,那我要添加字段该怎么办呢? 心里纠结 7 真是头痛,IDENTITY问题 怎样将A服务器的查询结果写到B服务器的表中!表的名字和结构都一样!! 高手看过来:这样的存储过程该如何写???? 怎样加入JPG/GIF文件入SQL SERVER中的IMAGE字段并能够显示?解决此问题者给100分!!!! 用事务发布订阅时出现的问题 怎样写一个生成定单号的存储过程
多谢..但是在不同的计算机里.
这样应该不行吧.
--同一一个数据库上
declare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)
insert @table1 values(2,'张三',22)
insert @table1 values(3,'李四',20)
declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)
insert @table2 values(2,'王俊',30)
insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from
(
select name,age from @table1
union
select name,age from @table2
) a order by a.age desc
select * from #tdrop table #t
比如查询出库A中的表a和库B中的表b中相同的某字段。该怎么写查询语句?谢谢大家帮忙!--创建链接服务器
exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','远程服务器名或ip地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用户名','密码'
go
--查询示例
select * from srv_lnk.A.dbo.a,B.dbo.b where 条件
--同一服务器上,不同的两个数据库
declare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)
insert @table1 values(2,'张三',22)
insert @table1 values(3,'李四',20)
declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)
insert @table2 values(2,'王俊',30)
insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from
(
select name,age from DataBase1.dbo.@table1 --数据库名.拥有者.表名
union
select name,age from DataBase2.dbo.@table2
) a order by a.age desc
select * from #tdrop table #t
--创建链接服务器
exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','远程服务器名或ip地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用户名','密码'
godeclare @table1 table(id int,name varchar(20),age int)insert @table1 values(1,'王俊',30)
insert @table1 values(2,'张三',22)
insert @table1 values(3,'李四',20)
declare @table2 table(id int,name varchar(20),age int)insert @table2 values(1,'李强',20)
insert @table2 values(2,'王俊',30)
insert @table2 values(3,'李四',20)select [id]=identity(int,1,1),a.* into #t from
(
select name,age from srv_lnk.DataBase1.dbo.@table1 --数据库名.拥有者.表名
union
select name,age from DataBase2.dbo.@table2
) a order by a.age desc
select * from #tdrop table #t