SQL ServerÖеÄT SQLµÄ»ù±¾¶ÔÏó
SQLµÄ»ù±¾¶ÔÏóÖ÷ÒªÓг£Á¿£¬±íʾ·û£¬·Ö¸ô·û£¬±£Áô¹Ø¼ü×Ö¡£
1¡¢³£Á¿
³£Á¿ÊÇÒ»¸ö°üº¬ÎÄ×ÖÓëÊý×Ö£¬Ê®Áù½øÖÆ»òÊý×Ö³£Á¿¡£Ò»¸ö×Ö·û´®³£Á¿°üº¬µ¥ÒýºÅ('')»òË«ÒýºÅ("")×Ö·û¼¯ÖеÄÒ»¸ö»ò¶à¸ö×Ö·û¡£
Èç¹ûÏëÔÚµ¥ÒýºÅ·Ö¸ôµÄ×Ö·û´®ÖÐÓõ½µ¥¶ÀµÄÒýºÅ£¬¿ÉÒÔÔÚÕâ¸ö×Ö·ûÖÐÓû§Á¬ÐøµÄµ¥ÒýºÅ£¨¼´ÓÃÁ½¸öµ¥ÒýºÅ±íʾµ¥ÒýºÅ£©¡£Ê®Áù½øÖƵij£Á¿±íʾ²»¿É´òÓ¡µÄ×Ö·û»òÕßÊÇÆäËû¶þ½øÖÆÊý¾Ý¡£Ã¿¸öÊ®Áù½øÖƳ£Á¿¶¼ÒÔ0x¿ªÍ·£¬ºóÃ渽´øÓÐ×Ö·û»òÕßÊý×Ö¡£
ÓÐЧ×Ö·û³£Á¿¾ÙÀý£º
"abc"
"ab .c"
"123"
'i don''t'
0xafec
²»ÊôÓÚ×Ö·û³£Á¿£º
'ab'c' --ÆæÊý¸öµ¥ÒýºÅ
'a" --ÒýºÅ²»ÊdzɶԵÄ
Êý×Ö³£Á¿°üº¬ËùÓÐÓмǺŻòû¼ÇºÅµÄÕûÊý¡¢¶¨µãÖµºÍ¸¡µãÊý¡£
ÒÔÏÂÊôÓÚÊý×Ö³£Á¿£º
130
-130
-0.351E5
Ò»¸ö³£Á¿Í¨³£ÓÐÒ»Ö±Êý¾ÝÀàÐͺͳ¤¶È£¬ÕâÈ¡¾öÓÚ³£Á¿µÄ¸ñʽ¡£
2¡¢·Ö¸ô·û
ÔÚT-SQLÖУ¬Ë«ÒýºÅÓÐÁ½²ãÒâ˼¡£³ýÁËÓ¦ÓÃ×Ö·û´®Ö®Í⣬˫ÒýºÅ»¹Äܹ»ÓÃÀ´×ö·Ö¸ô·û£¬Ò²¾ÍÊÇËùÓеĶ¨½ç±íʾ·û(delimited identifier)¡£·Ö¸ô±êʶ·ûÊDZêʶµÄÒ»ÖÖÌØÊâÀàÐÍ£¬Í¨³£½«±£Áô¹Ø¼ü×Öµ±×ö±êʶ·û²¢ÇÒÓÃÊý¾Ý¿â¶ÔÏóµÄÃû³ÆÃüÃû¿Õ¼ä¡£
×¢£ºµ¥ÒýºÅºÍË«ÒýºÅÖ®¼äµÄÇø±ð¾ÍÔÚÓÚÇ°ÕßÊÇÓÃÓÚSQL92±ê×¼¡£±êʶ·ûÕâÖÖÇé¿öÖУ¬ÕâÖÖ±ê×¼ÓÃÓÚÇø·Ö³£¹æºÍ·Ö¸ô·û¡£¹Ø¼üµÄÁ½µã¾ÍÊÇ·Ö¸ô·ûÊÇË«ÒýºÅÒý³öµÄ¶øÇÒ»¹Çø·Ö´óСд(T-SQL»¹Ö§³ÖÓû§·½À¨ºÅ([])À´´úÌæË«ÒýºÅ)¡£Ë«ÒýºÅÖ»ÓÃÓÚ·Ö¸ô×Ö·û´®¡£Ò»°ãÀ´Ëµ£¬·Ö¸ô±êʶ·û˵Ã÷Á˱êʶ·ûµÄ¹æ¸ñ£¬¶Ô±£Áô¹Ø¼ü×ÖÒ²ÆðÁËͬÑùµÄ×÷Ó᣷ָô±êʶ·û»¹¿ÉÒÔÈò»ÓÃÃû×Ö(±êʶ·û¡¢±äÁ¿Ãû)£¬ÕâЩÃû×ÖÒ²¿ÉÒÔÔÙ½«À´µÄSQL±ê×¼ÖÐÓÃÀ´×÷±£Áô¹Ø¼ü×Ö¡£²¢ÇÒ£¬·Ö¸ô±êʶ·û»¹¿ÉÄÜÔÚ±êʶ·ûÃûÖÖ°üº¬²»ºÏ¹æ¶¨µÄ×Ö·û£¬Èç¿Õ¸ñ¡£
ÔÚT-SQLµÄ»ù±¾¶ÔÏóÖУ¬Ê¹ÓÃË«ÒýºÅÊÇÀ´¶¨ÒåSETÓï¾äµÄQUOTE_IDENTIFIERÑ¡Ïî¡£Èç¹ûÕâһѡÏîÉèÖÃΪON£¨¼´Ä¬ÈÏÖµ£©£¬ÄÇô˫ÒýºÅÖеıêʶ·û¾Í±»¶¨Òå³ÉÁË·Ö¸ô·û¡£ÔÚÕâÖÖÇé¿öÏ¡£Ë«ÒýºÅ¾Í²»ÄÜÓÃÓÚ·Ö¸ô×Ö·û´®¡£
3¡¢±êʶ·û
T-SQLÖУ¬±êʶ·ûÓÃÓÚʧ°ÜÊý¾Ý¿â¶ÔÏóÈçÊý¾Ý¿â¡¢±íºÍË÷Òý£¬Í¨¹ý×Ö·û´®±íʾ³öÀ´£¬³¤¶È¿ÉÒÔ´ïµ½128¸ö×Ö·û£¬»¹°üº¬×Öĸ¡¢Êý¾Ý»òÕßÏÂÃæµÄ×Ö·û£º_¡¢@ºÍ#¡£Ã¿¸öÃû³Æ¶¼±ØÐëÒÔÒ»¸ö×Öĸ»òÕßÒÔÏÂ×Ö·ûÖеÄÒ»¸ö×Ö·û¿ªÍ·£º_¡¢@»ò#¡£#ÔÚÒÔËü¿ªÍ·µÄ±íÃ÷»òÕß´æ´¢³
Ïà¹ØÎĵµ£º
»ùÓÚË÷ÒýµÄSQLÓï¾äÓÅ»¯Ö®½µÁúÊ®°ËÕÆ
1 Ç°ÑÔ
¿Í·þÒµÎñÊܵ½SQLÓï¾äµÄÓ°Ïì·Ç³£´ó£¬ÔÚ¹æÄ£±È½Ï´óµÄ¾Öµã£¬ÍùÍùÒòΪһ¸öСµÄSQLÓï¾ä²»¹»ÓÅ»¯£¬µ¼ÖÂÊý¾Ý¿âÐÔÄܼ±¾çϽµ£¬Ð¡ÐÍ»úidleËùÊ£ÎÞ¼¸£¬Ó¦Ó÷þÎñÆ÷¶ÏÁ¬¡¢³¬Ê±£¬ÑÏÖØÓ°ÏìÒµÎñµÄÕý³£ÔËÐС£Òò´Ë£¬³ÆµÍЧµÄSQLÓï¾äΪ¿Í·þÒµÎñµÄ ......
On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs mig ......
1.¶àwhere£¬ÉÙhaving
whereÓÃÀ´¹ýÂËÐУ¬havingÓÃÀ´¹ýÂË×é
2.¶àunion all£¬ÉÙunion
unionɾ³ýÁËÖظ´µÄÐУ¬Òò´Ë»¨·ÑÁËһЩʱ¼ä
3.¶àExists£¬ÉÙin
ExistsÖ»¼ì²é´æÔÚÐÔ£¬ÐÔÄܱÈinÇ¿ºÜ¶à£¬ÓÐЩÅóÓѲ»»áÓÃExists£¬¾Í¾Ù¸öÀý×Ó
Àý£¬ÏëÒªµÃµ½Óе绰ºÅÂëµÄÈ˵Ļù±¾ÐÅÏ¢£¬table2ÓÐÈßÓàÐÅÏ¢
select * from table1;--(id,n ......
USE [sfaecrm]
GO
/****** ¶ÔÏó: StoredProcedure [dbo].[proc_insert] ½Å±¾ÈÕÆÚ: 05/29/2009 06:16:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[proc_insert] (@tablename varchar(256))
as
begin
set ......