Ô¶³Ì±¸·ÝsqlÊý¾Ý¿âµ½±¾»ú
Ìõ¼þ£º
ÓµÓÐsaȨÏÞ
¿ªÆô xp_cmdshell
·½·¨£º
¿ªÆô/¹Ø±Õ xp_cmdshell ±ØÐëÔÚ master ¿âÖ´ÐÐ
EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
--ÆôÓÃxp_cmdshell
EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'xp_cmdshell', 0
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
--¹Ø±Õxp_cmdshell
±¾µØ¿ªÆôÒ»¸ö¹²ÏíÎļþ¼Ð e.g. document
Ö´ÐÐÓï¾ä --ÒÔÏÂÔÚÒª±¾·Ö¿âÖ´ÐÐ
backup database dbname to disk= 'd:\backdbname.bak ' with init,password= ''
exec xp_cmdshell 'net use z: \\192.168.36.38\document " " /user:des-dev3\rfq '
exec xp_cmdshell 'copy d:\backdbname.bak z:\'
exec xp_cmdshell 'net use z: /delete '
ÔÀí ͨ¹ýsqlÖ¸ÁîÔÚ·þÎñÆ÷½¨Á¢Ò»¸öÍøÂç´ÅÅÌ Ö¸Ïò ±¾»ú¹²ÏíÎļþ¼Ð ·þÎñÆ÷±¸·ÝÊý¾Ý¿âµ½·þÎñÆ÷һĿ¼
ͨ¹ýsql Ö¸Áîcopy ±¸·ÝÎļþµ½ÍøÂç´ÅÅÌ
ɾ³ýÍøÂç´ÅÅÌ
Ïà¹ØÎĵµ£º
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname from tableName -- ´íÎó,²»»áÌáʾ´í ......
SQLÖÐCONVERTº¯Êý×î³£ÓõÄÊÇʹÓÃconvertת»¯³¤ÈÕÆÚΪ¶ÌÈÕÆÚ
Èç¹ûֻҪȡyyyy-mm-dd¸ñʽʱ¼ä, ¾Í¿ÉÒÔÓà convert(nvarchar(10),field,120)
120 ÊǸñʽ´úÂë, nvarchar(10) ÊÇָȡ³öÇ°10λ×Ö·û.
SELECT CONVERT(nvarchar(10), getdate(), 120)
SELECT CONVERT(varchar(10), getdate(), 120)
SELECT CONVERT(char(10), ge ......
sqlÓï¾ä£¬È¡³ö±íAÖеĵÚ31Ìõµ½40Ìõ¼Ç¼£¨±íAÒÔ×Ô¶¯Ôö³¤µÄID×öÖ÷¼ü£¬×¢ÒâID¿ÉÄÜÊDz»Á¬ÐøµÄ£©
-->select top 10 * from a where id not in (select top 30 id from a order by id) order by id
²éѯǰʮÌõ¼Ç¼£¬µ«Ìõ¼þÊÇ£ºID²»ÔÚÇ°ÈýÊ®ÌõµÄIDÀïÃæ
-->select top 10 * from (select top 40 ......
»ùÓÚSQL Server ·ÖÒ³´æ´¢¹ý³ÌµÄÑݽø ÊÕ²Ø
Õë¶ÔÊý¾Ý¿âÊý¾ÝÔÚUI½çÃæÉϵķÖÒ³ÊÇÀÏÉú³£Ì¸µÄÎÊÌâÁË£¬ÍøÉϺÜÈÝÒ×ÕÒµ½¸÷Ö֓ͨÓô洢¹ý³Ì”´úÂ룬¶øÇÒÓÐЩ»¹¶¨ÖƲéѯÌõ¼þ£¬¿´ÉÏȥʹÓúܷ½±ã¡£±ÊÕß´òËãͨ¹ý±¾ÎÄÒ²À´¼òµ¥Ì¸Ò»Ï»ùÓÚSQL SERVER 2000µÄ·ÖÒ³´æ´¢¹ý³Ì£¬Í¬Ê±Ì¸Ì¸SQL SERVER 2005Ï·ÖÒ³´æ´¢¹ý³ÌµÄÑ ......
--»ùÓÚʱ¼äSQLº¯Êý--
getdate() --·µ»Øµ±Ç°ÏµÍ³ÈÕÆÚºÍʱ¼ä¡£
DateAdd --ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ¡£
DATEADD ( datepart , number, date )
--Àý£ºÏòµ±ÌìµÄʱ¼äÔö¼Ó5Ìì
select dateadd(dd,5,getdate())
datediff --·µ»Ø¿çÁ½¸öÖ¸¶¨ÈÕÆÚµÄÈÕÆÚºÍʱ¼ä±ß½çÊý¡£]
---ÀýÈç
& ......