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 ×Ó¾äÖжÔ×ֶνøÐ
Ïà¹ØÎĵµ£º
ǶÈëSQLÓïÑÔ:
ÎÒ½«Ò»¸ösqlÁ´½Óµ½Êý¾Ý¿â£¬¸ÃÊý¾Ý¿âÃûΪmaster(ϵͳÊý¾Ý¿â)
then ¸øÊý¾Ý¿âÌí¼ÓÐÂ±í£¬½¨Á¢Èý¸ökey£ºuserid(int),name(char(10)),password(char(10))
ÔÚ´°ÌåÖÐŪÈý¸ötextbox¿Ø¼þ£¬·Ö±ð¶¨ÒåNameÊôÐÔΪuserid,name,password;
ÔÙÀ´Ò»¸öbutton
ÒÔÏÂÊÇForm1.csÖеĴúÂë
using System;
using System.Coll ......
Êý¾Ý¿â²Ù×÷Àࣺ
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
/// <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 serverÖо³£»áת»»stringµ½datetimeÀàÐÍ£¬×î³£Óõĺ¯Êý¾ÍÊÇConvert¡£ÄÇô¶ÔConvertÕâ¸öº¯Êý£¬²»µÃ²»ÏêϸµÄÑо¿Ò»Ï¡£ConvertÕâ¸öº¯ÊýµÄ¹¦ÄܺÜÇ¿´ó£¬¸ñʽÓֺܼòµ¥CONVERT ( data_type [ ( length ) ] , expression [ , style ] )¡£µ¥¾Í½«stringµ½datetimeÀàÐ͵Äת»»¾ÍÓкܶàÑùʽ¡£Èç: Convert(datetime, expression), ......
ÔÚwindows XP SP3 ÖÐÊÇ¿ÉÒÔ°²×° SQL Server 2005 µÄ²»»áÓмæÈÝÎÊÌâ ÎÒÔÚ°²×°µÄʱºò¾ÍʲôÎÊÌⶼû¿´µ½ °²×°ºÃºó¸½¼ÓÒ»¸öÊý¾Ý¿â ÓÃBorland JBuilder 2006 Enterprise ºÍeclipse ҲûÎÊÌâ
SQL2005 ·ÖÎå¸ö°æ±¾£¬ÈçÏÂËùÁУ¬
¡¡¡¡1.Enterprise(ÆóÒµ°æ),
2.Development(¿ª·¢°æ),
¡¡¡¡3.Workgroup,(¹¤×÷Ⱥ°æ)
¡¡¡¡4.St ......
Ëùν¶à·þÎñÆ÷¹ÜÀí (Multiserver Administration)¾ÍÊÇSQL Server 2008 R2ÌṩµÄ×Ô¶¯¹ÜÀí¶à¸ö SQL Server ʵÀý¹ý³ÌµÄ¹¦ÄÜ¡£ÔÚ¶à·þÎñÆ÷¹ÜÀíÖУ¬Á¬½Óµ½Ö÷·þÎñÆ÷²¢´ÓÆä½ÓÊÕ×÷ÒµµÄ·þÎñÆ÷±»³ÆÖ®ÎªÄ¿±ê·þÎñÆ÷¡£SQL Server 2008 R2ÍÆ³öÁ˹ÜÀíSQL·þÎñÆ÷Êý¾Ý¿âÒýÇæµÄ¶à¸öʵÀýµÄSQL·þÎñÆ÷¹¤¾ß£¬Ê¹ÓÃÕâЩ¹¤¾ß¿ÉÒÔͨ¹ýÖÐÑë·þÎñÆ÷¶Ô¶à¸öSQL ......