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

SQL Server·ÖÒ³3ÖÖ·½°¸

 SQL Server·ÖÒ³3ÖÖ·½°¸±ÈÆ´
´ËתÔØÔ´×ÔÀîºé¸ùµÄblog.×÷ÕßÊÇ΢ÈíµÄMVP!Ï£Íû´ó¼Ò²Î¿¼ÒÔÏÂ3ÖÖ·½°¸,°´Êµ¼ÊÇé¿öÑ¡Ôñ!
½¨Á¢±í£º
CREATE TABLE [TestTable] (
 [ID] [int] IDENTITY (1, 1) NOT NULL ,
 [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Note] [nvarchar] (2000) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
 
²åÈëÊý¾Ý£º(2ÍòÌõ£¬Óøü¶àµÄÊý¾Ý²âÊÔ»áÃ÷ÏÔһЩ)
SET IDENTITY_INSERT TestTable ON
declare @i int
set @i=1
while @i<=20000
begin
    insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, 'FirstName_XXX','LastName_XXX','Country_XXX','Note_XXX')
    set @i=@i+1
end
SET IDENTITY_INSERT TestTable OFF
 
-------------------------------------
·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º
SELECT TOP 10 *
from TestTable
WHERE (ID NOT IN
          (SELECT TOP 20 id
         from TestTable
         ORDER BY id))
ORDER BY ID
SELECT TOP Ò³´óС *
from TestTable
WHERE (ID NOT IN
          (SELECT TOP Ò³´óС*Ò³Êý id
         from ±í
         ORDER BY id))
ORDER BY ID
-------------------------------------
·ÖÒ³·½°¸¶þ£º(ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT TOP·ÖÒ³£©
Óï¾äÐÎʽ£º
SELECT TOP 10 *
from TestTable
WHERE (ID >
          (SELECT MAX(id)
         from (SELECT TOP 20 id
                 from TestTable
                 ORDER BY


Ïà¹ØÎĵµ£º

SQLÓï¾äµÄÓÅ»¯

 SQLÓï¾ä¼¶±ðµÄÓÅ»¯ÊÇÎÒÃÇʵ¼Ê¹¤×÷ÖнӴ¥×î¶àµÄ£¬¼¸ºõËùÓеÄÊý¾Ý¿âÓ¦ÓÃ˵µ½µ×¶¼ÊÇSQLÓï¾äµÄ¾ßÌåÖ´ÐУ¬Òò´ËÈçºÎ¶ÔSQL½Å±¾±¾Éí½øÐÐÓÅ»¯£¬Ìá¸ßÖ´ÐÐЧÂʾÍÏÔµÃÓÈΪÖØÒª¡£ÒÔÏÂÊÇһЩͨÓõÄÉè¼ÆÔ­Ôò¡£
   (1)ʹÓÃselectÓï¾ä²éѯʱ£¬¾¡Á¿²»ÒªÊ¹ÓÃselect *¡¡Óï¾ä£¬¶øÊÇÓ¦¸ÃÖ¸Ã÷¾ßÌåÒª²éѯµÄ×ֶΣ¬ÌáÈ¡µÄ×Ö¶ÎÊýÁ¿Ô½É ......

SQL ×¢Èë




SQL×¢Èë¾Í²»ÓýéÉÜÁË£¬ÍøÉϺܶࡣÏÂÃæ½éÉÜһϷÀÖ¹
SQL×¢ÈëµÄ·½·¨¡£
ʹÓÃ
quotename º¯ÊýºÍ
sp_executesql
²Î¿¼Èç
ϱí½á¹¹£ºÕâÊÇÒ»¸öÎĵµ±íÀïÃæÓÐһЩ¼òµ¥µÄ×Ö¶ÎÐÅÏ¢
CREATE
TABLE
[dbo]
.
[DocumentInfo]
(
    [ID]
[int]
IDENTITY
(
1,
1) primary key
 NOT
......

ÓÃSQLÓï¾ä´´½¨±í&ÓÃSQLÓï¾ä´´½¨Êý¾Ý¿â

Êý¾Ý¿âÖеÄËùÓÐÊý¾Ý´æ´¢ÔÚ±íÖС£Êý¾Ý±í°üÀ¨ÐкÍÁС£Áоö¶¨Á˱íÖÐÊý¾ÝµÄÀàÐÍ¡£Ðаüº¬ÁËʵ¼ÊµÄÊý¾Ý¡£ 
ÀýÈ磬Êý¾Ý¿âpubsÖеıíauthorsÓоŸö×ֶΡ£ÆäÖеÄÒ»¸ö×Ö¶ÎÃûΪΪau_lname£¬Õâ¸ö×ֶα»ÓÃÀ´´æ´¢×÷ÕßµÄÃû×ÖÐÅÏ¢¡£Ã¿´ÎÏòÕâ¸ö±íÖÐÌí¼ÓÐÂ×÷Õßʱ£¬×÷ÕßÃû×־ͱ»Ìí¼Óµ½Õâ¸ö×ֶΣ¬²úÉúÒ»ÌõмǼ¡£ 
ͨ¹ý¶¨Òå×ֶ䪎 ......

±È½ÏOracle SQLÖеÄIN & EXISTS

ÔÚOracle SQLÖÐÈ¡Êý¾ÝʱÓÐʱҪÓõ½in ºÍ exists ÄÇôËûÃÇÓÐʲôÇø±ðÄØ£¿
1 ÐÔÄÜÉϵıȽÏ
±ÈÈçSelect * from T1 where x in ( select y from T2 )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
select *
  from t1, ( select distinct y from t2 ) t2
 where t1.x = t2.y;
숦﵀
select * from t1 where exists ( select null fro ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ