Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ServerÖÐ charÓëvarchar  

¹Ì¶¨³¤¶È(char)Óë¿É±ä³¤¶È(varchar)×Ö·ûÊý¾ÝÀàÐÍ
char[(n)]
³¤¶ÈΪn¸ö×ֽڵĹ̶¨³¤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪn¸ö×Ö½Ú¡£charÔÚSQL-92ÖеÄͬÒå´ÊΪcharacter¡£
varchar[(n)]
³¤¶ÈΪn¸ö×ֽڵĿɱ䳤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪÊäÈëÊý¾ÝµÄ×Ö½ÚµÄʵ¼Ê³¤¶È£¬¶ø²»ÊÇn¸ö×Ö½Ú¡£ËùÊäÈëµÄÊý¾Ý×Ö·û³¤¶È¿ÉÒÔΪÁã¡£varcharÔÚSQL-92ÖеÄͬÒå´ÊΪchar varying»òcharacter varying¡£
ÓÉÓÚcharÊÇÒԹ̶¨³¤¶ÈµÄ£¬ËùÒÔËüµÄËÙ¶È»á±Èvarchar¿ìµÃ¶à!µ«³ÌÐò´¦ÀíÆðÀ´ÒªÂé·³Ò»µã£¬ÒªÓÃtrimÖ®ÀàµÄº¯Êý°ÑÁ½±ßµÄ¿Õ¸ñÈ¥µô!
×¢ÊÍ
Èç¹ûûÓÐÔÚÊý¾Ý¶¨Òå»ò±äÁ¿ÉùÃ÷Óï¾äÖÐÖ¸¶¨n£¬ÔòĬÈϳ¤¶ÈΪ1¡£Èç¹ûûÓÐʹÓÃCASTº¯ÊýÖ¸¶¨n£¬ÔòĬÈϳ¤¶ÈΪ30¡£
½«ÎªÊ¹ÓÃchar»òvarcharµÄ¶ÔÏó±»Ö¸ÅÉÊý¾Ý¿âµÄĬÈÏÅÅÐò¹æÔò£¬³ý·ÇÓÃCOLLATE×Ó¾äÁíÍâÖ¸ÅÉÁËÌØ¶¨µÄÅÅÐò¹æÔò¡£¸ÃÅÅÐò¹æÔò¿ØÖÆÓÃÓÚ´æ´¢×Ö·ûÊý¾ÝµÄ´úÂëÒ³¡£
Ö§³Ö¶àÓïÑÔµÄÕ¾µãÓ¦¿¼ÂÇʹÓÃUnicode nchar»ònvarcharÊý¾ÝÀàÐÍÒÔ¾¡Á¿¼õÉÙ×Ö·ûת»»ÎÊÌâ¡£Èç¹ûʹÓÃchar»òvarchar£º
Èç¹ûÏ£ÍûÁÐÖеÄÊý¾ÝÖµ´óС½Ó½üÒ»Ö£¬ÇëʹÓÃchar¡£
Èç¹ûÏ£ÍûÁÐÖеÄÊý¾ÝÖµ´óСÏÔÖø²»Í¬£¬ÇëʹÓÃvarchar¡£
Èç¹ûÖ´ÐÐCREATE TABLE»òALTER TABLEʱSET ANSI_PADDINGΪOFF£¬ÔòÒ»¸ö¶¨ÒåΪNULLµÄcharÁн«±»×÷Ϊvarchar´¦Àí¡£
µ±ÅÅÐò¹æÔò´úÂëҳʹÓÃË«×Ö½Ú×Ö·ûʱ£¬´æ´¢´óСÈÔȻΪn¸ö×Ö½Ú¡£¸ù¾Ý×Ö·û´®µÄ²»Í¬£¬n¸ö×ֽڵĴ洢´óС¿ÉÄÜСÓÚn¸ö×Ö·û¡£


Ïà¹ØÎĵµ£º

SQLÓï¾ä´óÈ«(3)

--Óï ¾ä¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT¡¡¡¡¡¡--´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT¡¡¡¡¡¡--ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE¡¡¡¡¡¡--´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE¡¡¡¡¡¡--¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE¡¡¡¡--´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE¡¡¡¡ --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER ......

SQLº¯Êý¿â

1.×Ö·û´®º¯Êý £º
datalength(Char_expr) ·µ»Ø×Ö·û´®°üº¬×Ö·ûÊý,µ«²»°üº¬ºóÃæµÄ¿Õ¸ñ
length(expression,variable)Ö¸¶¨×Ö·û´®»ò±äÁ¿Ãû³ÆµÄ³¤¶È¡£
substring(expression,start,length) ²»¶à˵ÁË,È¡×Ó´®
right(char_expr,int_expr) ·µ»Ø×Ö·û´®ÓÒ±ßint_expr¸ö×Ö·û
concat(str1,str2,...)·µ»ØÀ´×ÔÓÚ²ÎÊýÁ¬½áµÄ×Ö·û´®¡£dat ......

°ïÖúÄã´ÓMySQLÒÆÖ²µ½SQL ServerµÄ¹¤¾ß£¨SSMA£©

For SQL Server2008:
http://www.microsoft.com/downloads/details.aspx?FamilyID=0e6168b0-2d0c-4076-96c2-60bd25294a8e&displaylang=en
For SQL Server2005:
http://www.microsoft.com/downloads/details.aspx?familyid=C6F14640-DA22-4604-AAAA-A45DE4A0CD4A&displaylang=en ......

SQL Server 2008 ¾«ÃîÖ®´¦

±¾ÎĽéÉÜÁËSQL Server 2008ÀïһЩеÄÌØµãÒÔ¼°·¢ÏÖµÄһЩ¾«ÃîÖ®´¦……
¡¡¡¡°²×°
¡¡¡¡SQL
Server
2008µÄÉèÖúͰ²×°Ò²ÓÐËù¸Ä½ø¡£ÅäÖÃÊý¾ÝºÍÒýÇæÎ»ÒѾ­·Ö¿ªÁË£¬ËùÒÔËüʹ´´½¨»ù±¾µÄδÅäÖÃϵͳµÄ´ÅÅÌͼÏñ±äµÃ¿ÉÄÜÁË£¬Ëüʹ·Ö²¼µ½¶à¸ö·þÎñÆ÷±äµÃ¸üÈÝÒ×ÁË¡£
´Ó΢ÈíµÄÕ¾µãÒ²¿ÉÒÔÕÒµ½°²×°¿ÉÓõÄ×îиüС£ÁíÒ»¸öÌØµ ......

SQL ServerÀïµÄ ISNULL Óë Oracle ÖÐµÄ NULLIF

SQL ServerÀïµÄ ISNULL Óë Oracle ÖÐµÄ NULLIF²»Í¬:
  SQL Server ÖÐÓÐÁ½¸ö²ÎÊý£¬Óï·¨£º
    ISNULL(check_expression, replacement_value)
    check_expression Óë replacement_value Êý¾ÝÀàÐͱØÐëÒ»ÖÂ
   
Èç¹û check_expression Ϊ NULL£¬Ôò·µ»Ø replacement_v ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ