±È½ÏÁ½¸öSQLµÄÖ´ÐÐʱ¼ä
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PROC_SQL_COMP]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[PROC_SQL_COMP]
GO
/*--²âÊÔÁ½×éSQLµÄƽ¾ùʱ¼ä
ÀûÓÃosql.exeÀ´²âÊÔÁ½×é SQL Óï¾äµÄÖ´ÐÐʱ¼ä
²âÊԵĴ洢¹ý³ÌÖÐ,µ÷ÓÃÁËÊÂÎñ´¦Àí,ËùÒÔÈç¹û²âÊÔµÄSQLÓï¾äÓÐÊý¾ÝÐÞ¸ÄÐÐΪ
»áÔÚµ÷ÓýáÊøºó×Ô¶¯»Ø¹öÊÂÎñ,È·±£²âÊÔ²»»áÐÞ¸ÄÊý¾Ý
ÒÑÖªµÄÎÊÌâ:
1.ÓÉÓÚ osql µ÷Óò»ÔÊÐíʹÓöàÐÐ,ËùÒÔ´æ´¢¹ý³ÌÖлá°Ñ»Ø³µ»»ÐÐÌæ»»³É¿Õ¸ñ
¶ÔÓÚ SQL ×Ö·û´®ÖеĻسµ»»ÐÐ,Ò»Ñù»á±»Ìæ»»,ËùÒÔ¶ÔÓÚ×Ö·û´®Öаüº¬»Ø
³µ»»ÐÐµÄ SQL Óï¾ä,¿ÉÄÜ»á²úÉúÎÊÌâ,³ý·Ç»Ø³µ»»Ðв»¶Ô SQL Óï¾ä²úÉúÓ°Ïì
2.ÓÉÓÚÊǵ÷Óà xp_cmdshell À´Ö´ÐÐ osql,ËùÒÔÒªÇóÓÐϵͳ¹ÜÀíÔ±µÄȨÏÞ(±ÈÈçsa)
3.µ÷Óà osql ʹÓÃÁËwindowsÉí·ÝÑéÖ¤,ÕâÑùÊ¡È¥ÁËÖ¸¶¨Óû§Ãû¼°ÃÜÂëµÄÂé·³
µ«Èç¹ûÄãµÄ sql server ½ûÓÃÁËwindowsÉí·ÝÑéÖ¤,ÔòÐèÒªÐ޸Ĵ洢¹ý³ÌµÄ osql µ÷ÓÃ
--×Þ½¨ 2004.08(ÒýÓÃÇë±£Áô´ËÐÅÏ¢)--*/
/*--µ÷ÓÃʾÀý
exec dbo.PROC_SQL_COMP
'select top 1 * from sysobjects a,sysobjects b',
'select re=''1''
union all select 2'
--*/
create proc dbo.PROC_SQL_COMP
@sql1 varchar(7000), --²âÊԵĵÚÒ»¸ösqlÓï¾ä
@sql2 varchar(7000), --²âÊԵĵڶþ¸ösqlÓï¾ä
@t int=3 --²âÊÔ´ÎÊý
as
set nocount on
declare @s1 varchar(8000),@s2 varchar(8000),@tt varchar(20),@head varchar(8000)
declare @tb sysname
set @tb='tempdb.dbo.[temp_'+cast(newid() as varchar(36))+']'
exec('create table '+@tb+'(id int identity(0,1),m int)')
select @s1=replace(replace(@sql1,'''',''''''''''),char(13)+char(10),' ')
,@s2=replace(replace(@sql2,'''',''''''''''),char(13)+char(10),' ')
,@tt=cast(@t as varchar)
,@head='exec master..xp_cmdshell ''osql /E /d"'+db_name()+'"'
--ʹÓÃÁËwindowsÉí·ÝÑéÖ¤,Èç¹û²»Ö§³Ö,Ôò¸Ä /E Ϊ /U"sa" /P"ÃÜÂë"
exec(@head+' /Q"set xact_abort on;declare @i int,@a datetime;set @i=0;while @i<'
+@tt+' begin select @i=@i+1,@a=getdate();begin tran;exec('''''+@s1
ÔÚ´óÐ͵ÄÊý¾Ý¿âÓ¦ÓÃÖУ¬¾³£»áÓöµ½²¿·ÖÊý¾ÝµÄÍÑ»úºÍ¶à¸öÊý¾Ý¿âµÄºÏ²¢ÎÊÌâ¡£±ÈÈçÏÖÔÚÓÐÒ»¸öÈ«Ê¡·¶Î§Ê¹ÓõÄÓ¦ÓóÌÐò£¬Ã¿¸öÊж¼²¿ÊðÁ˵¥¶ÀµÄÏàͬµÄÓ¦ÓóÌÐò·þÎñÆ÷ºÍÊý¾Ý¿â·þÎñÆ÷£¬Ã¿¸öÔÂÐèÒª½«È«Ê¡ËùÓÐÊеÄÊý¾ÝÈ«²¿»ã×ÜÆðÀ´ÓÃÓÚ³öÈ«Ê¡µÄ±¨±í£¬ÕâÊÇÒ»Öֺܳ£¼ûµÄÊý¾Ý¿âºÏ²¢ÎÊÌâ¡£ÔÙ±ÈÈçÎÒÃÇ×öÁËÒ»¸öSmartClientµÄÓ¦ÓóÌÐò£¬Ã¿¸ö¿ ......
ÔÚWindows 2003 sp1·þÎñÆ÷ÉÏȱʡ°²×° MS SQL Server 2005 ¼òÌåÖÐÎÄÆóÒµ°æ£¬ÔÚÁ¬½Ó·þÎñÆ÷ʱÏÔʾ“²»ÔÊÐíÔ¶³ÌÁ¬½Ó”¡£
¾ßÌåÏÔʾÈçÏ£º(xxxxxsqlΪ·þÎñÆ÷Ãû£¬ÔÚ±¾µØ²Ù×÷)
C:\Documents and Settings\Administrator>sqlcmd -S xxxxxsql
HResult 0x2£¬¼¶±ð 16£¬×´Ì¬ 1
ÃüÃû¹ÜµÀÌṩ³ÌÐò: ÎÞ·¨´ò¿ªÓë SQL Server ......
´ó¼Ò´ò¿ªÕâ¸öÁ´½Ó¿ÉÒÔ¿´µ½ºÜ¶àÊý¾Ý¿âµÄÁ¬½Ó·½·¨¡£http://www.connectionstrings.com
ÕâЩÊý¾Ý¿âÖ®¼äµÄÊý¾Ý½»»»¾ÍÊÇÕâ¸öÌù×ÓËùÒª×ܽáµÄÄÚÈÝ¡£
£¨Ò»£©SQL ServerÖ®¼ä
°ÑÔ¶³ÌÊý¾Ý¿âÖеÄÊý¾Ýµ¼Èëµ½±¾µØÊý¾Ý¿â¡£
http://community.csdn.net/Expert/topic/5079/5079649.xml?temp=.7512018
http://community.csdn.net/Expert/ ......