Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ServerÈÕÆÚ²Ù×÷

1¡¢²éѯÁ½¸öʱ¼äÖ®¼ä
select * from [tablename] where date between \'value1\' and \'value2\'
 
2¡¢ÏÔʾ×îºó»Ø¸´Ê±¼ä
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
 
3¡¢Èճ̰²ÅÅÌáÇ°5·ÖÖÓÌáÐÑ
select * from Èճ̰²ÅÅ where datediff('minute',f¿ªÊ¼Ê±¼ä,getdate())>5
 
4¡¢ÅжÏÊÇ·ñΪÈòÄê
SELECT case day(dateadd(mm, 2, dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)))) when 28 then 'ƽÄê' else 'ÈòÄê' end
 
5¡¢±È½Ï2¸öÈÕÆÚ²îСÓÚ1·ÖÖÓ¡£ÈÕÆÚ¸ñʽΪyyyy-MM-dd HH:mm:ss
DATEDIFF(MS,TIME1,TIME2)<1
 
6¡¢»ñÈ¡µ±ÔÂ×ÜÌìÊý
select DATEDIFF(dd,getdate(),DATEADD(mm, 1, getdate()))
select datediff(day,dateadd(mm, datediff(mm,'',getdate()), ''),
dateadd(mm, datediff(mm,'',getdate()), '1900-02-01'))
 
--WAITFOR
--Àý µÈ´ý1 Сʱ2 ·ÖÁã3 Ãëºó²ÅÖ´ÐÐSELECT Óï¾ä
waitfor delay ’01:02:03’
select * from employee
--Àý µÈµ½ÍíÉÏ11 µãÁã8 ·Öºó²ÅÖ´ÐÐSELECT Óï¾ä
waitfor time ’23:08:00’
select * from employee
 
1.      µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä
        select getdate()
2. dateadd      ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
       ÀýÈ磺ÏòÈÕÆÚ¼ÓÉÏ2Ìì
       select dateadd(day,2,'2004-10-15')      --·µ»Ø£º2004-10-17 00:00:00.000
3. datediff ·µ»Ø¿çÁ½¸öÖ¸¶¨ÈÕÆÚµÄÈÕÆÚºÍʱ¼ä±ß½çÊý¡£
       select datediff(day,'2004-09-01','2004-09-18')       --·µ»Ø£º17
       select datediff(day,'2004-09-18','2004-09-01')       --·µ»Ø£º-17
4. datepart ·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
      SELECT DATEPART(month, '2004-10-15')      --·µ»Ø 10
5. datename ·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄ×Ö·û´®
   


Ïà¹ØÎĵµ£º

SQL Server´æ´¢¹ý³ÌÖÐraiserrorµÄʹÓÃ


Ò» ϵͳԤ¶¨Òå´íÎó´úÂë
SQL Server ÓÐ3831¸öÔ¤¶¨Òå´íÎó´úÂ룬ÓÉmaster.dbo.sysmessages±íά»¤¡£Ã¿Ò»¸ö´íÎó´úÂ붼ÓÐÏàÓ¦µÄ¼¶±ðºÍÃèÊö¡£
´íÎó¶¨ÒåµÄ¼¶±ð´Ó0µ½25¡£20ÒÔÉϵĴíÎó´ú±íÖØ´ó´íÎó£¬Í¨³£ÒâζןôíÎó»áµ¼Ö´洢½ø³ÌÁ¢¿ÌÖÕÖ¹£¬²¢ÇÒËùÓеĿͻ§Á¬½Ó¶¼ÒªÖØгõʼ»¯¡£
·Ç¹Ø¼üÐÔ´íÎóÖ»ÊǽûÖ¹µôµ±Ç°ÔËÐеijÌÐòÐУ¬²¢¼Ì ......

SQL²åÈëÓï¾ä£¨INSERT INTO £©

INSERT INTO
 tableName ( columnName1, columnName2, columnName3, columnName4)
VALUES      (  '45', 'Î÷²Ø°ì',  TO_Date( '2010-03-10 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), NULL,);
commit; ......

SQL ServerʾÀý²éѯ

Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
  select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
  fr ......

SQLÓï¾äÔÚJavaScriptÖеÄÓ¦ÓÃ

×î½üÒ»Ö±ÔÚÓÃjavascriptÔÚ×öÏîÄ¿
¿ÉÊÇ×ö×Å×ö×Å
¸Ð¾õºÜ¶à¹¦ÄÜ´úÂ붼ÊÇÖظ´µÄ¡£
±ÈÈç¶ÔjavascriptÊý×éµÄÅÅÐò
»¹ÓжÔÊý×éÊý¾ÝµÄɾѡÒÔ¼°·Ö×é
ËùÒÔ£¬ºóÀ´ÐËÖÂÒÔÉÏÀ´¡£
Ò»·¢²»¿ÉÊÕÊ°¡£
дÁËÒ»¸öÄÜÔÚjavascriptÖÐÓ¦ÓÃµÄ SQL ¿â
ºóÀ´ÓÖÏ룬Ôõô²»ÄÜÓÃjavascriptÖ±½ÓÁ¬½ÓÊý¾Ý¿âÄØ£¿
ÓÖ×öÁËÒ»¸öjavascriptÖ±Á¬SqlÊý¾ÝµÄÀà¿â ......

SQL server µÚÈýƪ ¶à±íÁª½Ó²éѯ

        ¶à±íÁª½Ó²éѯ
Ò»¡¢¶à±íÁª½Ó²éѯµÄ·ÖÀà
¶à±íÁª½Ó²éѯʵ¼ÊÉÏÊÇͨ¹ý¸÷¸ö±íÖ®¼ä¹²Í¬ÁеĹØÁªÐÔÀ´²éѯÊý¾ÝµÄ£¬ËüÊǹØϵÊý¾Ý¿â²éѯ×îÖ÷ÒªµÄÌØÕ÷¡£
Áª½Ó²éѯ¿É·ÖΪÈý´óÀ࣬·ÖÁíΪ£º
1£®  ÄÚÁª½Ó¡£
2£®  ÍâÁª½Ó¡£
3£®  ½»²æÁª½Ó¡£
ÄÇôÎÒÃÇÒ»ÆðÀ´¿´Ò»ÏÂÈçºÎʹÓö ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ