ÐÔÄܲâÊÔÖ®£º»áÒýÆðÈ«±íɨÃèµÄ¼¸ÖÖSql
1.
Ä£ºý²éѯЧÂʺܵͣº
ÔÒò£º
like
±¾ÉíЧÂʾͱȽϵͣ¬Ó¦¸Ã¾¡Á¿±ÜÃâ²éѯÌõ¼þʹÓÃ
like
£»¶ÔÓÚ
like ‘%...%’
£¨È«Ä£ºý£©ÕâÑùµÄÌõ¼þ£¬ÊÇÎÞ·¨Ê¹ÓÃË÷ÒýµÄ£¬È«±íɨÃè×ÔȻЧÂʺܵͣ»ÁíÍ⣬ÓÉÓÚÆ¥ÅäËã·¨µÄ¹Øϵ£¬Ä£ºý²éѯµÄ×ֶ㤶ÈÔ½´ó£¬Ä£ºý²éѯЧÂÊÔ½µÍ¡£
½â¾ö°ì·¨£ºÊ×ÏȾ¡Á¿±ÜÃâÄ£ºý²éѯ£¬Èç¹ûÒòΪҵÎñÐèÒªÒ»¶¨ÒªÊ¹ÓÃÄ£ºý²éѯ£¬ÔòÖÁÉÙ±£Ö¤²»ÒªÊ¹ÓÃÈ«Ä£ºý²éѯ£¬¶ÔÓÚÓÒÄ£ºý²éѯ£¬¼´
like ‘…%’
£¬ÊÇ»áʹÓÃË÷ÒýµÄ£»×óÄ£ºý
like
‘%...’
ÎÞ·¨Ö±½ÓʹÓÃË÷Òý£¬µ«¿ÉÒÔ
ÀûÓÃreverse + function index
µÄÐÎʽ£¬±ä»¯³É like
‘…%’
£»È«Ä£ºýÊÇÎÞ·¨ÓÅ»¯µÄ£¬Ò»¶¨ÒªµÄ»°¿¼ÂÇÓÃËÑË÷ÒýÇæ¡£³öÓÚ½µµÍÊý¾Ý¿â·þÎñÆ÷µÄ¸ºÔØ¿¼ÂÇ£¬¾¡¿ÉÄܵؼõÉÙÊý¾Ý¿âÄ£ºý²éѯ¡£
2.
²éѯÌõ¼þÖк¬ÓÐ
is null
µÄ
select
Óï¾äÖ´ÐÐÂý
ÔÒò£º
Oracle 9i
ÖУ¬²éѯ×Ö¶Î
is null
ʱµ¥Ë÷ÒýʧЧ£¬ÒýÆðÈ«±íɨÃè¡£
½â¾ö·½·¨£º
SQL
Óï·¨ÖÐʹÓÃ
NULL
»áÓкܶàÂé·³£¬
×îºÃË÷ÒýÁж¼ÊÇNOT NULL
µÄ£»¶ÔÓÚis null
£¬¿ÉÒÔ½¨Á¢×éºÏË÷Òý£¬nvl(
×Ö¶Î,0),
¶Ô±íºÍË÷Òýanalyse
ºó£¬is null
²éѯʱ¿ÉÒÔÖØÐÂÆôÓÃË÷Òý²éÕÒ,
µ«ÊÇЧÂÊ»¹²»ÊÇÖµµÃ¿Ï¶¨£»is not null
ʱÓÀÔ¶²»»áʹÓÃË÷Òý¡£Ò»°ãÊý¾ÝÁ¿´óµÄ±í²»ÒªÓÃis null
²éѯ¡£
3.
²éѯÌõ¼þÖÐʹÓÃÁ˲»µÈÓÚ²Ù×÷·û£¨
<>
¡¢
!=
£©µÄ
select
Óï¾äÖ´ÐÐÂý
ÔÒò£º
SQL
ÖУ¬²»µÈÓÚ²Ù×÷·û»áÏÞÖÆË÷Òý£¬ÒýÆðÈ«±íɨÃ裬¼´Ê¹±È½ÏµÄ×Ö¶ÎÉÏÓÐË÷Òý
½â¾ö·½·¨£ºÍ¨¹ý°Ñ²»µÈÓÚ²Ù×÷·û¸Ä³É
or
£¬¿ÉÒÔʹÓÃË÷Òý£¬±ÜÃâÈ«±íɨÃè¡£ÀýÈ磬°Ñ
column<>’aaa’
£¬¸Ä³É
column<’aaa’ or column>’aaa’
£¬¾Í¿ÉÒÔʹÓÃË÷ÒýÁË¡£
6.
ʹÓÃ×éºÏË÷Òý£¬Èç¹û²éѯÌõ¼þÖÐûÓÐÇ°µ¼ÁУ¬ÄÇôË÷Òý²»Æð×÷Ó㬻áÒýÆðÈ«±íɨÃ裻µ«ÊÇ´ÓOracle9i
¿ªÊ¼£¬ÒýÈëÁËË÷ÒýÌøԾʽɨÃèµÄÌØÐÔ£¬¿ÉÒÔÔÊÐíÓÅ»¯Æ÷ʹÓÃ×éºÏË÷Òý£¬¼´±ãË÷ÒýµÄÇ°µ¼ÁÐûÓгöÏÖÔÚWHERE
×Ó¾äÖС£ÀýÈ磺create index skip1 on emp5(job,empno);
È«Ë÷ÒýɨÃè select count(*) from emp5 where empno=7900;
Ë÷ÒýÌøԾʽɨÃè select /*+ index(emp5 skip1)*/ count(*) from emp5 where empno=7900;
Ç°Ò»ÖÖÊÇÈ«±íɨÃ裬ºóÒ»ÖÖÔò»áʹÓÃ×
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¡¡¡¡Êµ¼ÊÉÏ£¬Äú¿ÉÒÔ°ÑË÷ÒýÀí½âΪһÖÖÌØÊâµÄĿ¼¡£Î¢ÈíµÄsql serverÌṩÁËÁ½ÖÖË÷Òý£º¾Û¼¯Ë÷Òý£¨clustered index£¬Ò²³Æ¾ÛÀàË÷Òý¡¢´Ø¼¯Ë÷Òý£©ºÍ·Ç¾Û¼¯Ë÷Òý£¨nonclustered index£¬Ò²³Æ·Ç¾ÛÀàË÷Òý¡¢·Ç´Ø¼¯Ë÷Òý£©¡£ÏÂÃ棬ÎÒÃǾÙÀýÀ´ËµÃ÷һϾۼ¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷ÒýµÄÇø±ð£º
¡¡¡¡Æäʵ£¬ÎÒÃǵĺºÓï× ......
1.ijҽԺ²¡·¿¼ÆËã»ú¹ÜÀíÖÐÐèÒªÈçÏÂÐÅÏ¢£º£¨15·Ö£©
¿ÆÊÒ£º¿ÆÃû£¬¿ÆµØÖ·£¬¿Æµç»°
²¡·¿£º²¡·¿ºÅ£¬ËùÊô¿ÆÊÒÃû
Ò½Éú£ºÐÕÃû£¬Ö°³Æ£¬ËùÊô¿ÆÊÒÃû£¬ÄêÁ䣬¹¤×÷Ö¤ºÅ
²¡ÈË£º²¡ÀúºÅ£¬ÐÕÃû£¬ÐÔ±ð£¬Õï¶Ï£¬Ö÷¹ÜÒ½Éú£¬²¡·¿ºÅ£¬ÈëסÈÕÆÚ
ÆäÖУ¬Ò»¸ö¿ÆÊÒÓжà¸ö²¡·¿¡¢¶à¸öÒ½Éú£¬Ò»¸ö²¡·¿Ö»ÄÜÊôÓÚÒ»¸ö¿ÆÊÒ£¬Ò»¸öÒ½ÉúÖ»ÊôÓÚÒ»¸ö¿ÆÊÒ£¬µ«¿É¸º ......
//±¾³ÌÐòÁ¬½ÓµÄÊÇsql server 2005£¬ÓëÁ¬½Ósql server 2000Óе㲻ͬ£ºdriverNameºÍURL¶¼²»Í¬
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class create{
public void getConnection() th ......
¿Î³Ì½éÉÜ
SQL Server 2008ÊÇ΢ÈíµÄ×îÐÂÊý¾Ý¿âϵͳ,ÆäÔÚÔÓÐSQL Server 2005µÄ»ù´¡ÉÏ,½øÐÐÁËÖØ´óµÄ¸Ä½ø¡£±¾¿Î³Ì½«´Óά»¤Ó뿪·¢Á½¸ö·½Ãæ½øÐнÏϵͳµØ½²Êö£¬Ê¹Ñ§Ô±Äܹ»ÊìÁ·Ê¹ÓÃSQL Server 2008¿ª·¢Ç¿½¡µÄÊý¾Ý¿âÓ¦Óá£
Êʺ϶ÔÏó
Êý¾Ý¿â¹ÜÀí»ò¿ª·¢ÈËÔ±
¿Î³Ì³¤¶È
& ......