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

sql´óÊý¾Ý²Ù×÷ÈçºÎÓÅ»¯

¾ßÌåҪעÒâµÄ£º  
1.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺  
select id from t where num is null  
¿ÉÒÔÔÚnumÉÏÉèÖÃĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâÑù²éѯ£º  
select id from t where num=0  
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓÃ!=»ò<>²Ù×÷·û£¬·ñÔò½«ÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£ÓÅ»¯Æ÷½«ÎÞ·¨Í¨¹ýË÷ÒýÀ´È·¶¨½«ÒªÃüÖеÄÐÐÊý,Òò´ËÐèÒªËÑË÷¸Ã±íµÄËùÓÐÐС£  
3.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓà or À´Á¬½ÓÌõ¼þ£¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺  
select id from t where num=10 or num=20  
¿ÉÒÔÕâÑù²éѯ£º  
select id from t where num=10  
union all  
select id from t where num=20  
4.in ºÍ not in Ò²ÒªÉ÷Óã¬ÒòΪIN»áʹϵͳÎÞ·¨Ê¹ÓÃË÷Òý,¶øÖ»ÄÜÖ±½ÓËÑË÷±íÖеÄÊý¾Ý¡£È磺  
select id from t where num in(1,2,3)  
¶ÔÓÚÁ¬ÐøµÄÊýÖµ£¬ÄÜÓà between ¾Í²»ÒªÓà in ÁË£º  
select id from t where num between 1 and 3  
5.¾¡Á¿±ÜÃâÔÚË÷Òý¹ýµÄ×Ö·ûÊý¾ÝÖУ¬Ê¹Ó÷ǴòÍ·×ÖĸËÑË÷¡£ÕâҲʹµÃÒýÇæÎÞ·¨ÀûÓÃË÷Òý¡£  
¼ûÈçÏÂÀý×Ó£º  
SELECT * from T1 WHERE NAME LIKE ‘%L%’  
SELECT * from T1 WHERE SUBSTING(NAME,2,1)=’L’  
SELECT * from T1 WHERE NAME LIKE ‘L%’  
¼´Ê¹NAME×ֶν¨ÓÐË÷Òý£¬Ç°Á½¸ö²éѯÒÀÈ»ÎÞ·¨ÀûÓÃË÷ÒýÍê³É¼Ó¿ì²Ù×÷£¬ÒýÇæ²»µÃ²»¶ÔÈ«±íËùÓÐÊý¾ÝÖðÌõ²Ù×÷À´Íê³ÉÈÎÎñ¡£¶øµÚÈý¸ö²éѯÄܹ»Ê¹ÓÃË÷ÒýÀ´¼Ó¿ì²Ù×÷¡£  
6.±ØҪʱǿÖƲéѯÓÅ»¯Æ÷ʹÓÃij¸öË÷Òý£¬ÈçÔÚ where ×Ó¾äÖÐʹÓòÎÊý£¬Ò²»áµ¼ÖÂÈ«±íɨÃè¡£ÒòΪSQLÖ»ÓÐÔÚÔËÐÐʱ²Å»á½âÎö¾Ö²¿±äÁ¿£¬µ«ÓÅ»¯³ÌÐò²»Äܽ«·ÃÎʼƻ®µÄÑ¡ÔñÍƳٵ½ÔËÐÐʱ£»Ëü±ØÐëÔÚ±àÒëʱ½øÐÐÑ¡Ôñ¡£È»¶ø£¬Èç¹ûÔÚ±àÒëʱ½¨Á¢·ÃÎʼƻ®£¬±äÁ¿µÄÖµ»¹ÊÇδ֪µÄ£¬Òò¶øÎÞ·¨×÷ΪË÷ÒýÑ¡ÔñµÄÊäÈëÏî¡£ÈçÏÂÃæÓï¾ä½«½øÐÐÈ«±íɨÃ裺  
select id from t where num=@num  
¿ÉÒÔ¸ÄΪǿÖƲéѯʹÓÃË÷Òý£º  
select id from t with(index(Ë÷ÒýÃû)) where num=@num  
7.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐ


Ïà¹ØÎĵµ£º

asp.net½áºÏaspnetpagerÓÃsqlÓï¾ä·ÖÒ³

Êý¾Ý¿â²Ù×÷Àࣺ
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
/// <summary>
/// È¡µÃ×ÜÊý
/// </summary>
/// <returns></returns>
public string getTotal()
{
StringBuilder sb = new StringBuilder();
sb.Append("select count(*) total from Test");
DataTable dt = DBHelper.ExecuteDt(sb.ToString ......

SQL string to date time

ÔÚSQL serverÖо­³£»áת»»stringµ½datetimeÀàÐÍ£¬×î³£Óõĺ¯Êý¾ÍÊÇConvert¡£ÄÇô¶ÔConvertÕâ¸öº¯Êý£¬²»µÃ²»ÏêϸµÄÑо¿Ò»Ï¡£ConvertÕâ¸öº¯ÊýµÄ¹¦ÄܺÜÇ¿´ó£¬¸ñʽÓֺܼòµ¥CONVERT ( data_type [ ( length ) ] , expression [ , style ] )¡£µ¥¾Í½«stringµ½datetimeÀàÐ͵Äת»»¾ÍÓкܶàÑùʽ¡£Èç: Convert(datetime, expression), ......

Óà SqlÌí¼Óɾ³ý×ֶΣ¬ÅжÏ×Ö¶ÎÊÇ·ñ´æÔڵķ½·¨

http://www.cnblogs.com/dwjaissk/archive/2006/07/25/459476.aspx
Ôö¼Ó×Ö¶Î
alter table docdsp  add dspcode char(200)
ɾ³ý×Ö¶Î
ALTER TABLE
table_NAME DROP COLUMN column_NAME
ÐÞ¸Ä×Ö¶ÎÀàÐÍ
ALTER TABLE table_name 
ALTER COLUMN column_name new_data_type
¸ÄÃû
sp_rename
¸ü¸Äµ±Ç°Êý¾Ý¿âÖÐ ......

sql²»³£¼ûÓï¾ä»ã×Ü

1¡¢join
A±íµÄÖ÷¼üÊÇ×÷ΪB±íµÄÍâ¼ü¡£ÔÚ²éѯµÄʱºò£¬¿ÉÒÔͨ¹ý²»Í¬µÄjoin½«AºÍB±íÁ´½ÓÆðÀ´£¬´Ó¶øµÃµ½²»Í¬µÄ²éѯ½á¹û¡£
* JOIN: Èç¹û±íÖÐÓÐÖÁÉÙÒ»¸öÆ¥Å䣬Ôò·µ»ØÐÐ
* INNER JOIN: Èç¹ûÁ½¸ö±íÖÐÓÐÆ¥ÅäµÄ£¬Ôò·µ»ØÐР         
* LEFT JOIN: ¼´Ê¹ÓÒ±íÖÐûÓÐÆ¥Å䣬Ҳ´Ó×ó± ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ