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

SQL¾­µä¶ÌС´úÂëÊÕ¼¯

--SQL Server£º
Select TOP N * from TABLE Order By NewID() 
--Access£º
Select TOP N * from TABLE Order By Rnd(ID)  
Rnd(ID) ÆäÖеÄIDÊÇ×Ô¶¯±àºÅ×ֶΣ¬¿ÉÒÔÀûÓÃÆäËûÈκÎÊýÖµÀ´Íê³É£¬±ÈÈçÓÃÐÕÃû×Ö¶Î(UserName) 
Select TOP N *  from TABLE Order BY Rnd(Len(UserName)) 
--MySql£º
Select * from TABLE Order By Rand() Limit 10  
--¿ªÍ·µ½NÌõ¼Ç¼
Select Top N * from ±í
--Nµ½MÌõ¼Ç¼(ÒªÓÐÖ÷Ë÷ÒýID)
Select Top M-N * from ±íWhere ID in (Select Top M ID from ±í) Order by ID  Desc
--Ñ¡Ôñ10´Óµ½15µÄ¼Ç¼
select top 5 * from (select top 15 * from table order by id asc) table_±ðÃûorder by id desc 
--Nµ½½áβ¼Ç¼
Select Top N * from ±íOrder by ID Desc
 
--ÏÔʾ×îºó5Ìõ¼Ç¼,µ«ÊÇÏÔʾµÄ˳Ðò±ØÐëΪ5,6,7,8,9,10,¶ø²»ÊÇ10,9,8,7,6,5 ÈçϽâ¾ö·½·¨:
select top 5 from test where id in(select top 5 from test order by id desc) order by id asc
--ͨ¹ýÕâ¸öÎÊÌâÒ²ÄÜ×ܽá³ö4-10Ìõ,5-100ÌõÕâÖÖÏÞ¶¨Ò»¶¨·¶Î§ÄÚµÄsqlÓï¾äµÄд·¨:
select top <Ä©¶ËID-¶¥¶ËID+1> * from <±íÃû> where ID not in(select top <¶¥¶ËID-1>) ID from <±íÃû>)
--ÀýÈç:4-10Ìõ¾ÍÓ¦¸Ãд³É
select top 10-4+1 * from test where id not in(select top 4-1 id from test)
 ÉÏһƪ: select top 1 * from [news_table] where [ÐÂÎűêʶÁÐ]<µ±Ç°idºÅ where ......
 ÏÂһƪ: select top 1 * from [news_table] where [ÐÂÎűêʶÁÐ]>µ±Ç°idºÅ where ...... order by [ÐÂÎűêʶÁÐ] desc --Á½Ìõ¼Ç¼ÍêÈ«Ïàͬ£¬ÈçºÎɾ³ýÆäÖÐÒ»Ìõ
set rowcount=1 
delete from thetablename where id=@duplicate_id--@duplicate_idΪÖظ´ÖµµÄid 
--Ä£ºý²éѯ
select * &nbs


Ïà¹ØÎĵµ£º

¡¾»ã×Ü¡¿SQL CODE ¾­µä·¾«²Ê

Êý¾Ý²Ù×÷Àà SQLHelper.cs
http://www.cnblogs.com/zengxiangzhan/archive/2009/12/31/1636871.html
ÎÞÏÞ¼¶·ÖÀà ´æ´¢¹ý³Ì
http://www.cnblogs.com/zengxiangzhan/archive/2010/01/04/1639220.html
°ÙÍò¼¶·ÖÒ³´æ´¢
http://www.cnblogs.com/zengxiangzhan/archive/2009/09/12/1565313.html
SQL¾­µä¶ÌС´úÂëÊÕ¼¯
htt ......

SQL ϵͳ±í Sysobjects ºÍ SysColumns ±íµÄһЩ֪ʶ


syscolumns
ÿ¸ö±íºÍÊÓͼÖеÄÿÁÐÔÚ±íÖÐÕ¼Ò»ÐУ¬´æ´¢¹ý³ÌÖеÄÿ¸ö²ÎÊýÔÚ±íÖÐÒ²Õ¼Ò»ÐС£¸Ã±íλÓÚÿ¸öÊý¾Ý¿âÖС£
ÁÐÃûÊý¾ÝÀàÐÍÃèÊö
name
sysname
ÁÐÃû»ò¹ý³Ì²ÎÊýµÄÃû³Æ¡£
id
int
¸ÃÁÐËùÊôµÄ±í¶ÔÏó ID£¬»òÓë¸Ã²ÎÊý¹ØÁªµÄ´æ´¢¹ý³Ì ID¡£
xtype
tinyint
systypes ÖеÄÎïÀí´æ´¢ÀàÐÍ¡£
typestat
tinyint
½öÏÞÄÚ²¿Ê¹ ......

SQLÊý¾Ý¿â¿ìÕÕ


Êý¾Ý¿â¿ìÕÕÊÇMSSQL2005µÄй¦ÄÜ£¬½öÔÚ Microsoft SQL Server 2005 Enterprise Edition ÖпÉÓ᣶øÇÒSQL Server Management Studio ²»Ö§³Ö´´½¨Êý¾Ý¿â¿ìÕÕ£¬´´½¨¿ìÕÕµÄΨһ·½Ê½ÊÇʹÓà Transact-SQL¡£
Êý¾Ý¿â¿ìÕÕÊÇÊý¾Ý¿â£¨³ÆΪ“Ô´Êý¾Ý¿â”£©µÄÖ»¶Á¾²Ì¬ÊÓͼ¡£ÔÚ´´½¨Ê±£¬Ã¿¸öÊý¾Ý¿â¿ìÕÕÔÚÊÂÎñÉ϶¼ÓëÔ´Êý¾Ý¿âÒ»Ö ......

SQlÊý¾ÝÀàÐÍ( _ ѧSQL¾Í´ÓÊý¾ÝÀàÐÍ¿ªÊ¼°É£¡)

SQlÊý¾ÝÀàÐÍ(-_-ѧSQL¾Í´ÓÊý¾ÝÀàÐÍ¿ªÊ¼°É£¡)
bit    ÕûÐÍ
ÆäÖµÖ»ÄÜÊÇ0¡¢1»ò¿ÕÖµ¡£
ÕâÖÖÊý¾ÝÀàÐÍÓÃÓÚ´æ´¢Ö»ÓÐÁ½ÖÖ¿ÉÄÜÖµµÄÊý¾Ý£¬ÈçYes »òNo¡¢True »òFalse ¡¢On »òOff.
int    ÕûÐÍ 4¸ö×Ö½Ú
´Ó- 2^31(-2147483648)µ½2^31 (2147483 647)Ö®¼äµÄÕûÊý¡£
´æ´¢µ½Êý¾Ý¿âµÄ¼¸ºõËùÓÐÊýÖµÐ͵ÄÊý¾ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ