SQLÓï¾äÓÅ»¯¼¼Êõ·ÖÎö
Ò»¡¢²Ù×÷·ûÓÅ»¯
1¡¢IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģ¬´ÓOracleÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃINµÄSQLÓë²»ÓÃINµÄSQLÓÐÒÔÏÂÇø±ð£º
ORACLEÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç¼£¬Èç¹ûת»»³É¹¦ÔòÖ±½Ó²ÉÓöà¸ö±íµÄÁ¬½Ó·½Ê½²éѯ¡£Óɴ˿ɼûÓÃINµÄSQLÖÁÉÙ¶àÁËÒ»¸öת»»µÄ¹ý³Ì¡£Ò»°ãµÄSQL¶¼¿ÉÒÔת»»³É¹¦£¬µ«¶ÔÓÚº¬ÓзÖ×éͳ¼ÆµÈ·½ÃæµÄSQL¾Í²»ÄÜת»»ÁË¡£
ÍƼö·½°¸£ºÔÚÒµÎñÃܼ¯µÄSQLµ±Öо¡Á¿²»²ÉÓÃIN²Ù×÷·û£¬ÓÃEXISTS ·½°¸´úÌæ¡£
2¡¢NOT IN²Ù×÷·û
´Ë²Ù×÷ÊÇÇ¿Áв»ÍƼöʹÓõģ¬ÒòΪËü²»ÄÜÓ¦ÓñíµÄË÷Òý¡£
ÍƼö·½°¸£ºÓÃNOT EXISTS ·½°¸´úÌæ
3¡¢IS NULL »òIS NOT NULL²Ù×÷£¨ÅжÏ×Ö¶ÎÊÇ·ñΪ¿Õ£©
ÅжÏ×Ö¶ÎÊÇ·ñΪ¿ÕÒ»°ãÊDz»»áÓ¦ÓÃË÷ÒýµÄ£¬ÒòΪË÷ÒýÊDz»Ë÷Òý¿ÕÖµµÄ¡£
ÍƼö·½°¸£ºÓÃÆäËüÏàͬ¹¦ÄܵIJÙ×÷ÔËËã´úÌ棬È磺a is not null ¸ÄΪ a>0 »òa>’’µÈ¡£²»ÔÊÐí×Ö¶ÎΪ¿Õ£¬¶øÓÃÒ»¸öȱʡֵ´úÌæ¿ÕÖµ£¬ÈçÉêÇëÖÐ״̬×ֶβ»ÔÊÐíΪ¿Õ£¬È±Ê¡ÎªÉêÇë¡£
4¡¢> ¼° < ²Ù×÷·û£¨´óÓÚ»òСÓÚ²Ù×÷·û£©
´óÓÚ»òСÓÚ²Ù×÷·ûÒ»°ãÇé¿öÏÂÊDz»Óõ÷ÕûµÄ£¬ÒòΪËüÓÐË÷Òý¾Í»á²ÉÓÃË÷Òý²éÕÒ£¬µ«ÓеÄÇé¿öÏ¿ÉÒÔ¶ÔËü½øÐÐÓÅ»¯£¬ÈçÒ»¸ö±íÓÐ100Íò¼Ç¼£¬Ò»¸öÊýÖµÐÍ×Ö¶ÎA£¬30Íò¼Ç¼µÄA=0£¬30Íò¼Ç¼µÄA=1£¬39Íò¼Ç¼µÄA=2£¬1Íò¼Ç¼µÄA=3¡£ÄÇôִÐÐA>2ÓëA>=3µÄЧ¹û¾ÍÓкܴóµÄÇø±ðÁË£¬ÒòΪA>2ʱORACLE»áÏÈÕÒ³öΪ2µÄ¼Ç¼Ë÷ÒýÔÙ½øÐбȽϣ¬¶øA>=3ʱORACLEÔòÖ±½ÓÕÒµ½=3µÄ¼Ç¼Ë÷Òý¡£
5¡¢LIKE²Ù×÷·û
LIKE²Ù×÷·û¿ÉÒÔÓ¦ÓÃͨÅä·û²éѯ£¬ÀïÃæµÄͨÅä·û×éºÏ¿ÉÄÜ´ïµ½¼¸ºõÊÇÈÎÒâµÄ²éѯ£¬µ«ÊÇÈç¹ûÓõò»ºÃÔò»á²úÉúÐÔÄÜÉϵÄÎÊÌ⣬ÈçLIKE ‘%5400%’ ÕâÖÖ²éѯ²»»áÒýÓÃË÷Òý£¬¶øLIKE ‘X5400%’Ôò»áÒýÓ÷¶Î§Ë÷Òý¡£
Ò»¸öʵ¼ÊÀý×Ó£ºÓÃYW_YHJBQK±íÖÐÓªÒµ±àºÅºóÃæµÄ»§±êʶºÅ¿ÉÀ´²éѯӪҵ±àºÅ YY_BH LIKE ‘%5400%’ Õâ¸öÌõ¼þ»á²úÉúÈ«±íɨÃ裬Èç¹û¸Ä³ÉYY_BH LIKE ’X5400%’ OR YY_BH LIKE ’B5400%’ Ôò»áÀûÓÃYY_BHµÄË÷Òý½øÐÐÁ½¸ö·¶Î§µÄ²éѯ£¬ÐÔÄܿ϶¨´ó´óÌá¸ß¡£
6¡¢UNION²Ù×÷·û
UNIONÔÚ½øÐбíÁ´½Óºó»áɸѡµôÖظ´µÄ¼Ç¼£¬ËùÒÔÔÚ±íÁ´½Óºó»á¶ÔËù²úÉúµÄ½á¹û¼¯½øÐÐÅÅÐòÔËË㣬ɾ³ýÖظ´µÄ¼Ç¼ÔÙ·µ»Ø½á¹û¡£Êµ¼Ê´ó²¿·ÖÓ¦ÓÃÖÐÊDz»»á²úÉúÖظ´µÄ¼Ç¼£¬×î³£¼ûµÄÊǹý³Ì±íÓëÀúÊ·±íUNION¡£È磺
select * from gc_d
Ïà¹ØÎĵµ£º
Ò»¶Îʱ¼äÀ´£¬Ã¿ÌìµÄ¹¤×÷¶¼±È½ÏÔÓ£¬vb,asp,c#,sql£¬Ã¿Ï×÷¶¼Òª¸ã£¬ÊµÔÚÊÇÀÛ£¡¹¤×÷Ö®Ó࣬ÏëÏ빫˾ºÍ¹¤×÷µÄÇé¿ö£¬¿´À´ÊÇÓбØÒª»»¸ö»·¾³ÁË¡£²»¹ýÒ²ÒªÏÈ°ÑÄ¿Ç°µÄ¹¤×÷´¦ÀíÍê³É°¡¡£
×î½üÓÖÓöµ½Ò»¸öÎÊÌ⣺һ¼Ò¿Í»§Ê¹ÓÃÖеÄÊý¾Ý¿â£¬ÈÕÖ¾ÎļþÒì³£Ôö´ó£¬Æ½¾ùÿÌìÔö¼Ó´óÔ¼Ò»¸öG£¬¶øÊý¾ÝÎļþ±ä» ......
內Á¬½Ó½öÑ¡³öÁ½ÕűíÖл¥ÏàÆ¥ÅäµÄ¼Ç¼£®Òò´Ë£¬Õâ»áµ¼ÖÂÓÐʱÎÒÃÇÐèÒªµÄ¼Ç¼ûÓаüº¬½øÀ´¡£
Ϊ¸üºÃµÄÀí½âÕâ¸ö¸ÅÄÎÒÃǽéÉÜÁ½¸ö±í×÷ÑÝʾ¡£ËÕ¸ñÀ¼Òé»áÖеÄÕþµ³±í(party)ºÍÒéÔ±±í(msp)¡£¸´ÖÆÄÚÈݵ½¼ôÌù°å´úÂë:
party(Code,Name,Leader)
Code: Õþµ³´úÂë
Name: Õþµ³Ãû³Æ
Leader: Õþµ³ÁìÐä
msp(Nam ......
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE data ......
²Î¿¼¡¶ASP.NETÓëSQLÒ»Æð´ò°ü²¿Êð°²×°¡·£¬ÕâƪÎÄÕÂÊÇÕë¶ÔVB.NETÓëSQL Ò»Æð´ò°üµÄ,µ«ÊÇÎÒʹÓõÄÊÇC#,µ±È»Ö»ÒªÐÞ¸ÄÒ»ÏÂÖ÷Òª°²×°Àà¿â¾ÍÐÐÁË!C#µÄÀà¿â´úÂëÈçÏÂ:DBCustomAction.cs
using System;
using System.Collections;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration.Install; ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using AHUT_TetWebERP;
......