SQL SERVER Ò×»ìÏýµÄÊý¾ÝÀàÐÍ
(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)¡£
Ïà¹ØÎĵµ£º
SQLÖеÄʱ¼äº¯Êý·Ç³£ÓÐÓã¬ÌرðÊÇÔÚÎÒÃǽøÐгõʼ¸³Öµ¡¢¸´ÔÓ²éѯµÄʱºò£¬¾ÍÏÔµÃÌر𷽱㡣
1¡¢»ñµÃϵͳµ±Ç°Ê±¼ä
select getdate()
2¡¢DateName ( datepart , date )·µ»Ø±íʾָ¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄ×Ö·û´®¡£
--½ñÌìÊÇ2009-2-24--ÐÇÆÚ¶þ
SELECT DATENAME(year, getdate()) AS 'Year&nbs ......
Ò»£ºsql loader µÄÌصã
oracle×Ô¼º´øÁ˺ܶàµÄ¹¤¾ß¿ÉÒÔÓÃÀ´½øÐÐÊý¾ÝµÄǨÒÆ¡¢±¸·ÝºÍ»Ö¸´µÈ¹¤×÷¡£µ«ÊÇÿ¸ö¹¤¾ß¶¼ÓÐ×Ô¼ºµÄÌص㡣
±ÈÈç˵expºÍimp¿ÉÒÔ¶ÔÊý¾Ý¿âÖеÄÊý¾Ý½øÐе¼³öºÍµ¼³öµÄ¹¤×÷£¬ÊÇÒ»ÖֺܺõÄÊý¾Ý¿â±¸·ÝºÍ»Ö¸´µÄ¹¤¾ß£¬Òò´ËÖ÷ÒªÓÃÔÚÊý¾Ý¿âµÄÈȱ¸·ÝºÍ»Ö¸´·½Ãæ¡£ÓÐ×ÅËٶȿ죬ʹÓüòµ¥£¬¿ì½ÝµÄÓŵ㣻ͬʱҲÓÐһР......
×Ö·û´®º¯Êý¶Ô¶þ½øÖÆÊý¾Ý¡¢×Ö·û´®ºÍ±í´ïʽִÐв»Í¬µÄÔËËã¡£´ËÀຯÊý×÷ÓÃÓÚCHAR¡¢VARCHAR¡¢ BINARY¡¢ ºÍVARBINARY Êý¾ÝÀàÐÍÒÔ¼°¿ÉÒÔÒþʽת»»ÎªCHAR »òVARCHARµÄÊý¾ÝÀàÐÍ¡£¿ÉÒÔÔÚSELECT Óï¾äµÄSELECT ºÍWHERE ×Ó¾äÒÔ¼°±í´ïʽÖÐʹÓÃ×Ö·û´®º¯Êý¡£
Ò»¡¢×Ö·ûת»»º¯Êý
1¡¢ASCII()
·µ»Ø×Ö·û±í´ïʽ ......
µÚÒ»²¿·Ö
µ¥±í²éѯ
ÀýÒ»£º²éѯȫÌåѧÉúµÄѧºÅÓëÐÕÃû
SELECT Sno,Sname
from Student;
Àý¶þ£º²éѯȫÌåѧÉúµÄÐÕÃû¡¢Ñ§ºÅ¡¢ËùÔÚϵ
SELECT Sname,Sno,Sdept
from Student;
ÀýÈý£º²éѯȫÌåѧÉúµÄÏêϸ¼Ç¼
SELECT *
from Student;
µÈ¼ÛÓÚ£º
SELECT *
from Student;
ÀýËÄ£º²éѯȫÌåѧÉúµÄÐÕÃû¼°Æä³öÉúÄê·Ý
......
Êý¾Ý¿âsqlÓï¾äϵÁж¼ÊÇÒÔÏÂÃæµÄ±íΪ»ù´¡µÄ
1. д³ö²½Öè4Öеĸ÷Ïî²Ù×÷µÄSQLÓï¾ä¡£
¢Ù ¸øѧÉú±íÔö¼ÓÒ»ÊôÐÔNation£¨Ãñ×壩£¬Êý¾ÝÀàÐÍΪVarchar£¨20£©£»
alter table Student add Nation varchar(20);
¢Ú ɾ³ýѧÉú±íÖÐÐÂÔöµÄÊôÐÔNation£»
alter table Student DR ......