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;
===========================
³£ÓÃÓï¾ä£º
SELECT a.*
from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'd:\aaa.xls';'admin';'', data)
AS a
ÒÔÏÂÓï¾äÄܳɹ¦,ÉÏÒ»ÌìÓï¾äÈ´²»ÐÐ:OLE DB Ìṩ³ÌÐò 'Microsoft.Jet.OLEDB.4.0' ±¨´í¡£
[OLE/DB provider returned message: ²»¿Éʶ±ðµÄÊý¾Ý¿â¸ñʽ 'd:\aaa.xls'¡£]
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="d:\aaa.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...data$
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 'D
Ïà¹ØÎĵµ£º
¾ßÌå²½Ö裺
¡¡¡¡Ò».ÔÚ·þÎñÆ÷¶ËÒÔ
dbsrv7.exe pathyyy.db -n
ServiceName -x tcpip -q
¡¡¡¡Æô¶¯Êý¾Ý¿â£¬ÕâÀïÒ²¿ÉÒÔÖ¸¶¨¶Ë¿Ú£¬ÏêϸµÄ²ÎÊýÇëÓÃdbsrv7.exe /?»ñÈ¡¡£
¡¡¡¡-n servicename:Æô¶¯·þÎñÃûΪservicenameµÄÊý¾Ý¿â·þÎñÓÃÒÔ±ê¼ÇÍøÂçÊý¾Ý¿â·þÎñΨһ±ê¼Ç£»
¡¡¡¡-x tcpip£ºÊ¹ÓÃtcp/ipÐÒ飬ĬÈ϶˿Ú3362,×¢Òâ²»Òª± ......
EXECºÍsp_executesqlµÄÇø±ð£¿
DBCC FREEPROCCACHE --¡·Çå¿Õ»º´æÖеÄÖ´Ðмƻ®
SELECT cacheobjtype,objtype,usecounts,sql from sys.syscacheobjects WHERE sql NOT LIKE '%cach%' AND sql NOT LIKE '%sys.%' --¡·²éÕÒ¶ÔÓ¦µÄ»º´æÖеĶÔÓ¦¼Æ»®
SQL ServerΪÿһ¸öµÄ²éѯ×Ö·û´®´´½¨ÐµÄÖ´Ðмƻ®£¬¼´Ê¹²éѯģʽÏàͬҲÊÇÕâÑù
......
ºÜ¶àʱºò£¬ÎÒÃÇÐèÒª°ÑÊý¾Ý¿âSequenceÉèÖõ½Ä³¸öÌض¨µÄÖµ¿ªÊ¼£¬µ«ÊÇÓÖ²»ÏëÖؽ¨Õâ¸öSequence ÄÇÏÂÃæµÄSQLÓï¾ä¾Í¿ÉÒÔʵÏÖÕâÑùµÄ¹¦ÄÜ£º ÆäÖÐuser_seqÊÇÐèÒª²Ù×÷µÄSequenceÃû³Æ£¬1 .. 100ÊǵÝÔö100´Î DECLARE
rowCount1 NUMBER;
BEGIN
FOR cc IN 1 .. 100
LOOP
SELECT user_seq.NEXTVAL INTO rowCount1 f ......
Çë°´²½Öè½øÐУ¬Î´½øÐÐÇ°ÃæµÄ²½Öèʱ£¬Çë²»Òª×öºóÃæµÄ²½Ö裬ÒÔÃâËð»µÄãµÄÊý¾Ý¿â¡£
Ò»°ã²»½¨Òé×öµÚ4£¬6Á½²½£¬µÚ4²½²»°²È«£¬ÓпÉÄÜËð»µÊý¾Ý¿â»ò¶ªÊ§Êý¾Ý¡£µÚ6²½Èç¹ûÈÕÖ¾´ïµ½ÉÏÏÞ£¬ÔòÒÔºóµÄÊý¾Ý¿â´¦Àí»áʧ°Ü£¬ÔÚÇåÀíÈÕÖ¾ºó²ÅÄָܻ´¡£
1¡¢Çå¿ÕÈÕÖ¾
DUMP TRANSACTION ¿âÃû WITH NO_LOG
2¡¢½Ø¶ÏÊÂÎñÈÕÖ¾
B ......