易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL Server连接远程数据源

SQL Server连接远程数据源的基本方法有下面三种:
OPENDATASOURCE
: The OPENDATASOURCE function is used to
specify connection information for a remote data source by specifying
the OLE DB provider and an initialization string. OPENDATASOURCE can be
used directly within a SELECT, INSERT, UPDATE, or DELETE statement.
 
OPENROWSET
: The OPENROWSET function is used to specify
connection information for a remote data source and the name of an
object that will return a result set (such as a stored procedure) or a
query that will return a result set. Like OPENDATASOURCE, OPENROWSET
can be used directly within a SELECT, INSERT, UPDATE, or DELETE
statement.
 
Linked servers
: A linked server is an object within SQL
Server that defines the connection properties of another SQL Server.
When defined, queries can connect to the remote server using a
four-part name, such as
SQLSrv1.AdventureWorks.person.Contact
The four-part name identifies the server (SQLSrv1), the database
(AdventureWorks), the schema (Person), and the object (Contact table).
Linked servers are explored in more depth in the final section of this
chapter.
 
其中OPENDATASOURCE和OPENROWSET方法一般用来做临时查询(ad hoc query),如果需要经常的查询远程数据,则建议创建linked servers。但是,默认情况ad hoc query 是禁用的,需要手动启动:
sp_configure ‘show advanced options’, 1;
GO
RECONFIGURE;
GO
sp_configure ‘Ad hoc Distributed Queries’, 1;
GO
RECONFIGURE;
 
然后,就可以使用OPENDATASOURCE 查询远程数据库了,OPENDATASOURCE 基本语法如下:OPENDATASOURCE ( provider_name, init_string )。示例代码如下:
SELECT *
from OPENDATASOURCE(‘SQLNCLI’,
‘Data Source=SQL08;Integrated Security=SSPI’)
.Sales.dbo.Customers
上述代码从SQL08服务器上读取Sales数据库的Customers表的内容。
 
也可以通过OPENROWSET方法查询远程数据库,OPENROWSET和OPENDATASOURCE方法相似,基本的差异是
OPENROWSET总是返回结果集,而OPENDATASOURCE方法除了可以返回结果


相关文档:

select * into 和insert into SQL SERVER

select * into destTbl from srcTbl
insert into destTbl(fld1, fld2) select fld1, 5 from srcTbl
以上两句都是将 srcTbl 的数据插入到 destTbl,但两句又有区别的:
第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建。
第二句(insert into select from)要求目标表(dest ......

时间差计算: SQL Server DATEDIFF() 函数

SQL Server DATEDIFF() 函数
定义和用法
DATEDIFF() 函数返回两个日期之间的天数。
语法
DATEDIFF(datepart,startdate,enddate)
startdate 和 enddate 参数是合法的日期表达式。
datepart 参数可以是下列的值:
datepart缩写

yy, yyyy
季度
qq, q

mm, m
年中的日
dy, y

dd, d

wk, ww
星期 ......

简要介绍SQL Server 2008新的事件处理系统

SQL Server Extended Events(下面简称XEvent)是SQL Server 2008里新加的事件处理系统,用来取代SQL Server原
先的SQL Trace的跟踪机制。事件处理系统对一个复杂服务器系统的排错,调试是极为关键的。和SQL Server原来的事
件处理系统相比较,XEvent具有下列的优势:
  消耗更少的系统资源,更适用于在产品服务器上的 ......

hibernate 生成的 sql 语句 ? 代值

转自: http://hi.baidu.com/beanchx/blog/item/ed056509d66f65cc3bc763f4.html
p6spy的替代品:jdbc logger
2007年09月13日 下午 01:07
首先介绍一下这个开源的项目。这个是一个对jdbc中的sql进行logger的一个工具。若在项目中采用了较多的preparedStatement,那么打印出来的sql会有很多"?",非常不方便。有一个产品为p ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号