日期:2014-05-18  浏览次数:20638 次

数据库的一道应用题,求解!
题目有点忘了,大概就是这个意思:
有服务器server1,数据库database1,表table1,表里有字段,id(int),name(varchar),addtime(datetime)。还有一个服务器server2,也有数据库database1,表table2,表里有字段,id(int),name(varchar),addtime(datetime)。
问题:
A:用什么连接方式、如何连接能把两个服务器上的表里的数据全部显示到一个数据源(或一个表上)。
B:写出10-20之间的10条数据,id有可能不连续。
C:根据B能写出几种查询方式,比较各自的优点。
D:根据B的查询情况,写一个分页的存储过程,参数@PageSize(int),@page(int)。写出当前页的记录数,总行数,当前页数。

------解决方案--------------------
A:用什么连接方式、如何连接能把两个服务器上的表里的数据全部显示到一个数据源(或一个表上)。
-----------

select * into table1 from
openrowset( 'sqloledb ', 'IP '; 'sa '; ' ', 'select * from database1.dbo.table2 ')a
------解决方案--------------------
1.select top 10 * from table where id in(select top 20 * from table order by id desc)
2.select top 20 * into #table from table desc id
select top 10 from #table
3.select top 50% * from table where id not in(select top 20 * from table order by id asc)

俺写的咯~大家来评评~没试过~主要看思路看思路~呵呵
------解决方案--------------------
select top 10 id from balance where id > (select max(id) from (select top 10 id from balance) t)
------解决方案--------------------
select top 10 * from(select top 20 * from table order by id desc) a