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

²Ù×÷ÈÕÆÚµÄSQLÓï¾ä´óÈ«

1.ÏÔʾ±¾ÔµÚÒ»Ìì
SELECT DATEADD(mm,DATEDIFF(mm,0,getdate()),0)
select convert(datetime,convert(varchar(8),getdate(),
120)+’01’,120)
2.ÏÔʾ±¾ÔÂ×îºóÒ»Ìì
select dateadd(day,-1,convert(datetime,convert
(varchar(8),dateadd(month,1,getdate()),120)+’01’,120))
SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0))
3.ÉϸöÔµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(mm,0,getdate()),0))
4.±¾ÔµĵÚÒ»¸öÐÇÆÚÒ»i
select DATEADD(wk,DATEDIFF(wk,0, dateadd(dd,6-datepart(
day,getdate()),getdate())),0)
5.±¾ÄêµÄµÚÒ»Ìì
SELECT DATEADD(yy,DATEDIFF(yy,0,getdate()),0)
6.±¾ÄêµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate())+1,0))
7.È¥ÄêµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate()),0))
8.±¾¼¾¶ÈµÄµÚÒ»Ìì
SELECT DATEADD(qq,DATEDIFF(qq,0,getdate()),0)
9.±¾ÖܵÄÐÇÆÚÒ»
SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),0)
10.²éѯ±¾ÔµļǼ
select * from tableName where DATEPART(mm, theDate)
=DATEPART(mm, GETDATE()) and DATEPART(yy, theDate)
= DATEPART(yy, GETDATE())
11.²éѯ±¾ÖܵļǼ
select * from tableName where DATEPART(wk, theDate) = DATEPART
(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
12.²éѯ±¾¼¾µÄ¼Ç¼ ×¢£ºÆäÖÐ:GETDATE()ÊÇ»ñµÃϵͳʱ¼äµÄº¯Êý¡£
select * from tableName where DATEPART(qq, theDate) = DATEPART
(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
13.»ñÈ¡µ±ÔÂ×ÜÌìÊý:
select DATEDIFF(dd,getdate(),DATEADD
(mm, 1, getdate()))
select datediff(day,
dateadd(mm, datediff(mm,’’,getdate()), ’’),
dateadd(mm, datediff(mm,’’,getdate()), ’1900-02-01’))
14.»ñÈ¡µ±Ç°ÎªÐÇÆÚ¼¸
DATENAME(weekday, getdate())


Ïà¹ØÎĵµ£º

SQL Server ±ÊÊÔÌâ

Ò» µ¥´Ê½âÊÍ(2·Ö/¸ö) 34·Ö
¡¡¡¡Data Êý¾Ý Database Êý¾Ý¿â RDBMS ¹ØÏµÊý¾Ý¿â¹ÜÀíϵͳ GRANT ÊÚȨ
¡¡¡¡REVOKE È¡ÏûȨÏÞ DENY ¾Ü¾øÈ¨ÏÞ DECLARE ¶¨Òå±äÁ¿ PROCEDURE´æ´¢¹ý³Ì
¡¡¡¡ÊÂÎñ Transaction ´¥·¢Æ÷ TRIGGER ¼ÌÐø  continue Ψһ unqiue
¡¡¡¡Ö÷¼ü primary key  ±êʶÁÐ identity Íâ¼ü foreign key  ¼ì ......

SQL²éѯÖеÄתÒå×Ö·û ÀÁèÐÇ¿Õ

Èç¹ûÏë²éÕÒ“_cs”½áβµÄµÄÕË»§
select * from [user] where loginname like '%_cs'ÊDz»Ðеģ¬_ ±»ÈÏΪÊÇÈÎÒâµÄ×Ö·û£¬
ËùÒÔÐèҪתÒå×Ö·û£¬ÓÐÁ½ÖÖд·¨£º
select * from [user] where loginname like '%[_]cs'
select * from [user] where loginname like '%/_cs' escape'/'
ͨÅä·ûº¬Òå
%
°üº¬Áã¸ö»ò¸ü¶à×Ö· ......

SQL Server ±ÊÊÔÌâ(¶þ)

1)
¼Ù¶¨ÓÐÒ»¸öÓû§±í£¬±íÖаüº¬×ֶΣº
userid
(int)
¡¢
username
(varchar)
¡¢
password(varchar)
¡¢µÈ£¬
¸Ã±íÐèÒªÉèÖÃÖ÷¼ü£¬ÒÔÏÂ˵·¨ÕýÈ·µÄÊÇ£¨£©¡££¨Ñ¡ÔñÁ½Ï
  
a)
Èç¹û²»ÄÜÓÐÍ¬Ê±ÖØ¸´µÄ
username
ºÍ
password
£¬ÄÇô
username
ºÍ
password
¿ÉÒÔ×éºÏÔÚÒ»Æð×÷ΪÖ÷¼ü¡£
   ......

´¥·¢Æ÷»ñÈ¡Ð޸ıíµÄSQLÓï¾ä


/*
´¥·¢Æ÷»ñÈ¡SQLÓï¾äÔöÁ¿´«Êä
¹¦ÄÜ£º²¶×½Ð޸ıíµÄSQLÓï¾ä
ʹÓÃ˵Ã÷£º 1¡¢ÏÈн¨Ò»±íÊÖ¶¯Ð´ÈëÖ÷¼üÐÅÏ¢»òÕßΨһË÷Òý
   Create table prmary_key
   (tab_name varchar(255),
    key_name varchar(255))
   --´Ë±í½öÔÚ½¨Á¢´¥·¢Æ÷ʱʹÓ㬽¨ÍêËùÓд¥·¢Æ÷ºó ¼ÇµÃ ......

sql ²é±í¿Õ¼äÓï¾ä

SELECT UPPER(F.TABLESPACE_NAME) "±í¿Õ¼äÃû",
       D.TOT_GROOTTE_MB "±í¿Õ¼ä´óС(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "ÒÑʹÓÿռä(M)",
       TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_G ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ