SQL WHERE 1=1
1=1»òÕß'a'='a'µÈµÈºãµÈʽÊÇT-SQLÖбí´ïtrueµÄ·½·¨¡£ÒòΪÔÚT-SQLÖÐûÓÐtrueÕâÑùµÄ¹Ø¼ü
×Ö»òÖµ£¬ËùÒÔÐèÒª½èÖúÕâЩºãµÈʽÀ´±í´ïtrueµÄ¸ÅÄî¡£
Ïà¶ÔµÄ£¬Í¬Ñù¿ÉÒÔʹÓÃ1<>1»òÕß1=2µÈÀ´±í´ïfalse¡£
ÔÚÓ¦ÓóÌʽµÄ°²È«ÐÔ·½Ã棬ʹÓÃÕâЩʽ×ÓÊÇSQL×¢ÈëµÄ»ù±¾ÔÀí£¬ËùÒÔÔÚÆ´½ÓSQLÓï¾äµÄʱºòÒª¹ýÂ˸÷ÖÖ¸÷ÑùµÄÃô¸Ð×Ö
·û¡£
µ±È»£¬ÕâЩʽ×ÓÒ²ÓÐÓÐÓõĵط½¡£½ñÌì¿´µ½Ò»¸öͦÓÐÓõÄС¼¼ÇÉ£º
´ÓÒ»Õűí²éѯһЩ¼Ç¼£¬ÕâЩ¼Ç¼ÊǸù¾Ýname, age, height,
weightÀ´½øÐйýÂ˵ᣵ«ÊÇ£¬¾ßÌå¹ýÂËÌõ¼þµÄ¸öÊýÊDz»È·¶¨µÄ£¬±ÈÈçÓÐʱºò»áÊÇnameºÍageµÄ×éºÏ£¬ÓÐʱºò»áÊÇname,
heightºÍweightµÄ×éºÏ£¬ÉõÖÁÓÐʱºòûÓÐÈκÎÌõ¼þ¡£
Ôõô°ì£¿
Ò»°ãÐÔµÄÆ´½ÓSQLÓï¾äµÄ·½·¨»áÐèÒª×öÒ»¸öÅжϣºÔÚµÚÒ»¸öÌõ¼þÇ°Ãæ
¼ÓÉÏWHERE¹Ø¼ü×Ö¡£µ«ÊÇ£¬ÕâÑù×ö»áÐèÒªÌí¼ÓÒ»×éÅжϵÄÂß¼£¬ÒÔ¼ìÑéÊÇ·ñµ±Ç°µÄÌõ¼þÊǵÚÒ»¸öÌõ¼þ¡£
ÕâÀÒý½øWHERE 1=1¾Í¿ÉÒԺܺõÄÊ¡ÂÔµôÉÏÊöµÄÅжÏÂß¼¡£
Ôõô×öÄØ£¿´úÂëÈçÏ£º
string
query = "SELECT * from USERINFO WHERE 1=1"
if (_name != string.Empty)
{
query += " and name='" + _name + "'";
}
if
(_age != string.Empty)
{
query += " and age='" + _age + "'";
}
if (_height != string.Empty)
{
query += " and height='" + _height + "'";
}
if
(_weight != string.Empty)
{
query += " and weight='" + _weight + "'";
}
µ±È»£¬×îºÃ»¹ÊDz»ÒªÈ¥Æ´½ÓSQLÓï¾ä¿©£¬Ö±½ÓʹÓÃADOµÄ¶ÔÏóÊÇ×îʡʵķ½·¨¡£
±¾ÎÄÀ´×ÔCSDN²©¿Í£¬×ªÔØÇë±êÃ÷³ö´¦£º
http://blog.csdn.net/RogerXi/archive/2009/04/05/4050878.aspx
Ïà¹ØÎĵµ£º
DELETE from SCOTT.EMP;
DROP from SCOTT.EMP;
TRUNCATE from EMP;
Ïàͬµã
truncateºÍ²»´øwhere×Ó¾äµÄdelete, ÒÔ¼°drop¶¼»áɾ³ý±íÄÚµÄÊý¾Ý
²»Í¬µã:
1. truncateºÍ deleteֻɾ³ýÊý¾Ý²»É¾³ý±íµÄ½á¹¹(¶¨Òå)
dropÓï¾ä½«É¾³ý±íµÄ½á¹¹±»ÒÀÀµµÄÔ¼Êø(constrain),´¥·¢Æ÷(trigge ......
ǰЩÌì°²×°ÁËSQL Server2005£¬³öÁË2¸ö´íÎó£¬×îÖÕÔÚÍøÉÏÕÒµ½Á˽â¾ö°ì·¨£¬ÏÖÕûÀíһϡ£
´íÎóÒ»£º
½â¾ö·½·¨£º
ÓÃaspnet_regiisʵÓù¤¾ßжÔغÍÖØа²×°Ò»Ï¾ͿÉÒÔÁË¡£
¾ßÌåµÄ²Ù×÷ÈçÏ£º
½øÈëCMD£º
ÊäÈë cd c:\windows\microsoft.net\framework\v2.0.50727£¬½øÈë´ËÎļþ¼ÐĿ¼Ï£¬ÔËÐÐaspnet_regiis -uжÔØ
È»ºóÔËÐÐas ......
1¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏ
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö× ......
Çé¿ö£ºÎÒÒÔÇ°°²×°¹ýSQL Server 2000£¬Å¶£¬»¹ÓÐSQL Server 2005¡¢MySQLÄØ£¬ºóÀ´ÏµÍ³ÖØ×°ÁË£¬²»¹ýÕâЩӦÓóÌÐò¶¼ÔÚEÅÌÀ²»ÔÚϵͳÅÌÀ¾ÍÔÚ°²×°µÄʱºò³öÏÖÈçÏÂÈý¸ö´íÎó£¬ÔÚ´ËÖð¸ö½â¾ö˵Ã÷ÈçÏ£º
ÎÊÌâÒ»£º
±¨´íÐÅÏ¢£ºÒÔÇ°µÄij¸ö³ÌÐò°²×°ÒÑÔÚ°²×°¼ÆËã»úÉÏ´´½¨¹ÒÆðµÄÎļþ²Ù×÷¡£ÔËÐа²×°³ÌÐò֮ǰ±ØÐëÖØÐÂÆô¶¯¼ÆËã»ú¡£
½â¾ö·½ ......