ÔÚSQLÖÐʹÓÃnow()µ¼ÖµÄÐÔÄÜϽµ(MySQL)
×öÊý¾Ý¿âµ÷ÓÅ£¬Ò»¸ö¼òµ¥µÄtip¾ÍʹÐÔÄÜÌáÉýÒ»´ó¿éʱ£¬±»°ïÖúµÄÈË×ÔÈ»ÊǸßÐ˶øÇҸм¤£¬ÎÒÒ²ÊÇÂúÐÄ»¶Ï²¡£ÓÃËùѧ°ïÖúÁËËûÈË£¬Ò²ËµÃ÷»¹ÊÇÓÐÒ»¼¼Ö®³¤µÄ£¬ÓÐÒ»ÃÅÄܹ»Ñø»î×Ô¼ºµÄÊÖÒÕ¡£Ò²ËãÊÇÊÖÒÕÈ˰¡¡£
ͬÊÂÈÃÎÒ°ïÖúÓÅ»¯£¬ÔÚslow query logÀï·¢ÏÖÓÐÁ½¸öSQLÖ´ÐеĴÎÊý×î¶à£¬²¢ÇÒÿ´Î¶¼ÔÚÁ½ÃëÒÔÉÏ¡£ÓÃexplain¿´ÁË£¬Ò²Î´·¢ÏÖË÷ÒýʹÓ÷½ÃæµÄÎÊÌâ¡£
×îºó°Ñ»³ÒɵÄÄ¿¹âÂäÔÚÁËSQL½áβ´¦µÄ>=now()ÉÏ£¬now()ÿ´Î¶¼ÐèÒª´ÓϵͳÖÐÈ¡£¬Òò´Ë¿ÉÄܻᵼÖÂÎÞ·¨Ê¹ÓÃquery cache¡£
Á˽âÁËÒ»ÏÂÐèÇó£¬Êµ¼ÊÕâÀï²¢²»ÐèÒªµ±Ê±µÄʱ¿Ì£¬Ö»ÐèÒªµ±ÌìµÄÈÕÆÚ¾ÍÐÐÁË¡£Òò´Ë½¨ÒéͬʰÑ>=now()¸Ä³É>=µ±Ç°ÈÕÆÚ£¬¶øµ±Ç°ÈÕÆÚÔÚ³ÌÐòÖÐÈ¡µÃ¡£
¹ûÈ»£¬ÐÔÄÜ´ó·ùÌá¸ß¡£
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
ÔÚSQLServerµÄÐÔÄܵ÷ÓÅÖУ¬ÓÐÒ»¸ö²»¿É±ÈÄâµÄÎÊÌ⣺ÄǾÍÊÇÈçºÎÔÚÒ»¶ÎÐèÒª³¤Ê±¼äµÄ´úÂë»ò±»Æµ·±µ÷ÓõĴúÂëÖд¦ÀíÁÙʱÊý¾Ý¼¯?±í±äÁ¿ºÍÁÙʱ±íÊÇÁ½ÖÖÑ¡Ôñ¡£ÈçºÎÈ·¶¨Ê²Ã´Ê±ºòÓÃÁÙʱ±í£¬Ê²Ã´Ê±ºòÓñí±äÁ¿ÄØ£¿ÁÙʱ±íºÍ±í±äÁ¿¶¼ÓÐÌØ¶¨µÄÊÊÓû·¾³¡£
¡¡¡¡±í±äÁ¿
¡¡¡¡±äÁ¿¶ ......
select ID,Item1,Item2,Item3,Item4
into #Temp
from (
select ID='200910',Item1='A',Item2='B',Item3='C',Item4='T1'
union all
select ID='200910',Item1='',Item2='B',Item3='C' ,Item4='G2'
union all
select ID='200910',Item1='A',Item2='D',Item3='C' ,Item4='T3'
union all
select ID='200910',Item ......
SQLÓï¾äÓÅ»¯£º
(1)¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWHERE×Ó¾äµÄĩβ.
(2)SELECT×Ó¾äÖбÜÃâʹÓà ‘ * ‘
(3)¼õÉÙ·ÃÎÊÊý¾Ý¿âµÄ´ÎÊý
·½·¨3 (¸ßЧ)?
SELECT A.EMP_NAME , A.SALARY , A.GRADE,
B.EMP_NAME , B.SALARY , B.GRADE
from EMP A,EMP B
WHERE A.EMP_NO = 342
AND B.EMP_NO = 291;
( ......
²éѯ card µÄ¼Ç¼ΪÁ½´ÎÒÔÉ쵀 card£¬¼Ç¼Êý:
select count(card), card from TableName group by card having count(card) > 1
¼¶Áª¸üУ¬¼¶ÁªÉ¾³ý:
ColumnName type not null constraint FK_Name foreign key(ColumnName) references PrimaryTable(ColumnName) on update/delete cascade
×Ô¶¯¼ÆËãÁÐ:
create tabl ......