sql×Ö¶ÎÀàÐÍ
(1)char¡¢varchar¡¢textºÍnchar¡¢nvarchar¡¢ntext
charºÍvarcharµÄ³¤¶È¶¼ÔÚ1µ½8000Ö®¼ä£¬ËüÃǵÄÇø±ðÔÚÓÚcharÊǶ¨³¤×Ö·ûÊý¾Ý£¬¶øvarcharÊDZ䳤×Ö·ûÊý¾Ý¡£Ëùν¶¨³¤¾ÍÊdz¤¶È¹Ì¶¨µÄ£¬µ±ÊäÈëµÄÊý¾Ý³¤¶ÈûÓдﵽָ¶¨µÄ³¤¶Èʱ½«×Ô¶¯ÒÔÓ¢ÎÄ¿Õ¸ñÔÚÆäºóÃæÌî³ä£¬Ê¹³¤¶È´ïµ½ÏàÓ¦µÄ³¤¶È£»¶ø±ä³¤×Ö·ûÊý¾ÝÔò²»»áÒÔ¿Õ¸ñÌî³ä¡£text´æ´¢¿É±ä³¤¶ÈµÄ·ÇUnicodeÊý¾Ý£¬×î´ó³¤¶ÈΪ2^31-1(2,147,483,647)¸ö×Ö·û¡£
ºóÃæÈýÖÖÊý¾ÝÀàÐͺÍÇ°ÃæµÄÏà±È£¬´ÓÃû³ÆÉÏ¿´Ö»ÊǶàÁ˸ö×Öĸ"n"£¬Ëü±íʾ´æ´¢µÄÊÇUnicodeÊý¾ÝÀàÐ͵Ä×Ö·û¡£Ð´¹ý³ÌÐòµÄÅóÓѶÔUnicodeÓ¦¸ÃºÜÁ˽⡣×Ö·ûÖУ¬Ó¢ÎÄ×Ö·ûÖ»ÐèÒªÒ»¸ö×Ö½Ú´æ´¢¾Í×ã¹»ÁË£¬µ«ºº×ÖÖڶ࣬ÐèÒªÁ½¸ö×Ö½Ú´æ´¢£¬Ó¢ÎÄÓ뺺×Öͬʱ´æÔÚʱÈÝÒ×Ôì³É»ìÂÒ£¬Unicode×Ö·û¼¯¾ÍÊÇΪÁ˽â¾ö×Ö·û¼¯ÕâÖÖ²»¼æÈݵÄÎÊÌâ¶ø²úÉúµÄ£¬ËüËùÓеÄ×Ö·û¶¼ÓÃÁ½¸ö×Ö½Ú±íʾ£¬¼´Ó¢ÎÄ×Ö·ûÒ²ÊÇÓÃÁ½¸ö×Ö½Ú±íʾ¡£nchar¡¢nvarcharµÄ³¤¶ÈÊÇÔÚ1µ½4000Ö®¼ä¡£ºÍchar¡¢varchar±È½Ï£ºnchar¡¢nvarcharÔò×î¶à´æ´¢4000¸ö×Ö·û£¬²»ÂÛÊÇÓ¢ÎÄ»¹ÊǺº×Ö£»¶øchar¡¢varchar×î¶àÄÜ´æ´¢8000¸öÓ¢ÎÄ£¬4000¸öºº×Ö¡£¿ÉÒÔ¿´³öʹÓÃnchar¡¢nvarcharÊý¾ÝÀàÐÍʱ²»Óõ£ÐÄÊäÈëµÄ×Ö·ûÊÇÓ¢ÎÄ»¹ÊǺº×Ö£¬½ÏΪ·½±ã£¬µ«ÔÚ´æ´¢Ó¢ÎÄʱÊýÁ¿ÉÏÓÐЩËðʧ¡£
(2)datetimeºÍsmalldatetime
datetime£º´Ó1753Äê1ÔÂ1ÈÕµ½9999Äê12ÔÂ31ÈÕµÄÈÕÆÚºÍʱ¼äÊý¾Ý£¬¾«È·µ½°Ù·ÖÖ®ÈýÃë¡£
smalldatetime£º´Ó1900Äê1ÔÂ1ÈÕµ½2079Äê6ÔÂ6ÈÕµÄÈÕÆÚºÍʱ¼äÊý¾Ý£¬¾«È·µ½·ÖÖÓ¡£
(3)bitint¡¢int¡¢smallint¡¢tinyintºÍbit
bigint£º´Ó-2^63(-9223372036854775808)µ½2^63-1(9223372036854775807)µÄÕûÐÍÊý¾Ý¡£
int£º´Ó-2^31(-2,147,483,648)µ½2^31-1(2,147,483,647)µÄÕûÐÍÊý¾Ý¡£
smallint£º´Ó-2^15(-32,768)µ½2^15-1(32,767)µÄÕûÊýÊý¾Ý¡£
tinyint£º´Ó0µ½255µÄÕûÊýÊý¾Ý¡£
bit£º1»ò0µÄÕûÊýÊý¾Ý¡£
(4)decimalºÍnumeric
ÕâÁ½ÖÖÊý¾ÝÀàÐÍÊǵÈЧµÄ¡£¶¼ÓÐÁ½¸ö²ÎÊý£ºp£¨¾«¶È£©ºÍs£¨Ð¡ÊýλÊý£©¡£pÖ¸¶¨Ð¡Êýµã×ó±ßºÍÓұ߿ÉÒÔ´æ´¢µÄÊ®½øÖÆÊý×ÖµÄ×î´ó¸öÊý£¬p±ØÐëÊÇ´Ó 1µ½38Ö®¼äµÄÖµ¡£sÖ¸¶¨Ð¡ÊýµãÓұ߿ÉÒÔ´æ´¢µÄÊ®½øÖÆÊý×ÖµÄ×î´ó¸öÊý£¬s±ØÐëÊÇ´Ó0µ½pÖ®¼äµÄÖµ£¬Ä¬ÈÏСÊýλÊýÊÇ0¡£
(5)floatºÍreal
float£º´Ó-1.79^308µ½1.79^308Ö®¼äµÄ¸¡µãÊý×ÖÊý¾Ý¡£
real£º´Ó-3.40^38µ½3.40^38Ö®¼äµÄ¸¡µãÊý×ÖÊý¾Ý¡£ÔÚSQL ServerÖУ¬realµÄͬÒå´ÊΪfloat(24)¡£
Êý¾Ý¿â¶¨Òåµ½charÀàÐ͵Ä×Ö¶Îʱ£¬²»ÖªµÀ´ó¼ÒÊÇ·ñ»áÓÌԥһϣ¬µ½µ×Ñ¡char¡¢nchar¡¢varchar¡¢nvarchar¡¢text¡¢ntextÖ
Ïà¹ØÎĵµ£º
½ñÌìÔÚÍøÉÏÉÏ¿´¼ûһƪ“½«SQL²éѯ½á¹ûת»¯Îªpojo¶ÔÏóµÄ”²©¿Í£¬²©Ö÷×Ô¶¨Òå×öÁËÒ»¸öÀàÈçÏ£º
import java.lang.reflect.Field;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.property.ChainedPropertyAccessor;&n ......
1. SQLÓÅ»¯µÄÔÔòÊÇ£º
½«Ò»´Î²Ù×÷ÐèÒª¶ÁÈ¡µÄBLOCKÊý¼õµ½×îµÍ,¼´ÔÚ×î¶ÌµÄʱ¼ä´ïµ½×î´óµÄÊý¾ÝÍÌÍÂÁ¿¡£
µ÷Õû²»Á¼SQLͨ³£¿ÉÒÔ´ÓÒÔϼ¸µãÇÐÈ룺
¼ì²é²»Á¼µÄSQL£¬¿¼ÂÇÆäд·¨ÊÇ·ñ»¹ÓпÉÓÅ»¯ÄÚÈÝ
¼ì²é×Ó²éѯ ¿¼ÂÇSQL×Ó²éѯÊÇ·ñ¿ÉÒÔÓüòµ¥Á¬½Óµ ......
Õª×Ôhttp://hi.baidu.com/dusongw/blog/item/4090493d6ec0cdee3d6d97a6.html
ÎÒ½«ÒÔ“°ì¹«×Ô¶¯»¯”ϵͳΪÀý£¬Ì½ÌÖÈçºÎÔÚÓÐ×Å1000ÍòÌõÊý¾ÝµÄMS SQL SERVERÊý¾Ý¿âÖÐʵÏÖ¿ìËÙµÄÊý¾ÝÌáÈ¡ºÍÊý¾Ý·ÖÒ³¡£ÒÔÏ´úÂë˵Ã÷ÁËÎÒÃÇʵÀýÖÐÊý¾Ý¿âµÄ“ºìÍ·Îļþ”Ò»±íµÄ²¿·ÖÊý¾Ý½á¹¹£º
CREATE TABL ......
In:µÈÖµÁ¬½Ó£¬ÓÃÀ´²éÕÒ¶à±íÏàͬ×ֶεļǼ
Not In:·ÇµÈÖµÁ¬½Ó£¬ÓÃÀ´²éÕÒ²»´æÔڵļǼ
Inner join:ÄÚÁ¬½Ó£¬Ö÷ÒªÓÃÀ´²éÕÒ¶¼·ûºÏÌõ¼þµÄ¼Ç¼
Left join:×óÁ¬½Ó£¬Ö÷ÒªÓÃÀ´²éÕÒ×ó±ßÓУ¬ÓÒ±ßûÓеÄÓÿÕÖµ±í´ï
Right join:ÓÒÁ¬½Ó£¬Ö÷ÒªÓÃÀ´²éÕÒÓÒ±ßÓУ¬×ó±ßûÓеÄÓÿÕÖµ±í´ï
Order By:ÉýÐò Asc ½µÐò Desc
Group By:·Ö×éÅÅÐò ......
µ½½ñÌìΪֹ£¬ÈËÃǶԹØϵÊý¾Ý¿â×öÁË´óÁ¿µÄÑо¿£¬²¢¿ª·¢³ö¹ØϵÊý¾ÝÓïÑÔ£¬Îª²Ù×÷¹ØϵÊý¾Ý¿âÌṩÁË·½±ãµÄÓû§½Ó¿Ú¡£¹ØϵÊý¾ÝÓïÑÔÄ¿Ç°Óм¸Ê®ÖÖ£¬¾ßÓÐÔö¼Ó¡¢É¾³ý¡¢Ð޸ġ¢²éѯ¡¢Êý¾Ý¶¨ÒåÓë¿ØÖƵÈÍêÕûµÄÊý¾Ý¿â²Ù×÷¹¦ÄÜ¡£Í¨³£°ÑËüÃÇ·ÖΪÁ½Àࣺ¹Øϵ´úÊýÀàºÍ¹ØϵÑÝËãÀà¡£
ÔÚÕâЩÓïÑÔÖУ¬½á¹¹»¯²éѯÓïÑÔSQLÒÔÆäÇ¿´óµÄÊý¾Ý¿â²Ù× ......