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

Sql ÀïÃæ ROW_NUMBER Ó¦Óó¡¾°

ROW_NUMBER ·µ»Ø°´Ò»¶¨¹æÔòÅÅÐòµÄµ±Ç°¼Ç¼¶ÔÓ¦µÄÐкÅ
±ÈÈçÎÒÃÇÓÐÕâÑùÒ»¸öÓ¦Óó¡¾°£º
ÏÖÔÚÓиö±ÈÈü£¬ÐèÒª´ÓÍøÉϲÎÈüÕß´Ó´ÓÍøÂçÉϱ¨Ãû£¬È»ºóÈ¥×îÔ籨ÃûµÄ5¸öÈ˲μӱÈÈü£¬Îª´ËÎÒÃÇʵÏÖÈçÏ£º
1.Ϊ´ËÎÒÃÇÒª½¨Á¢Ò»ÕűíÀ´±£´æ±¨Ãû²ÎÈüÕßµÄÐÕÃû¼°Æð±¨Ãûʱ¼ä
CREATE 
TABLE [dbo].[UserEnroll](
[UserName] [nvarchar]
(50) NULL, --²ÎÈüÕßµÄÐÕÃû
[EnrollTime] [datetime]
NULL --±¨Ãûʱ¼ä

ON  [PRIMARY]
2.ÎÒÃÇSql Ïò±íÖвåÈëÊý¾Ý£¬Ä£Äâ²ÎÈüÕß±¨Ãû 
insert
  into [dbo].[UserEnroll] values('CC', GETDATE())
insert  into [dbo].[UserEnroll] values('CC1', DateAdd(DAY,-1,GETDATE()))
insert 
into [dbo].[UserEnroll] values('CC2', DateAdd(DAY,-2,GETDATE()))
insert 
into [dbo].[UserEnroll] values('CC3', DateAdd(DAY,-3,GETDATE()))
insert 
into [dbo].[UserEnroll] values('CC4', DateAdd(DAY,-4,GETDATE ()))
insert 
 into [dbo].[UserEnroll] values('CC5', DateAdd(DAY,-5,GETDATE()))
insert 
 into [dbo].[UserEnroll] values('CC6', DateAdd(DAY,-6,GETDATE()))
insert
 into [dbo].[UserEnroll] values('CC7', DateAdd(DAY,-7,GETDATE()))
 
3.ɾ³ý·Ç×îÔç5±¨ÃûµÄÈË
  a.  ¸ø±í¼ÓÉÏÐкÅ
SELECT
*, ROW_NUMBER() OVER(ORDER BY EnrollTime) AS RowNum
from [dbo].[UserEnroll]
   ½á¹ûÈçÏ£º
   UserName EnrollTime RowNum
CC7 2010-05-11 17:38:42.403 1
CC6 2010-05-12 17:38:42.403 2
CC5 2010-05-13 17:38:42.403 3
CC4 2010-05-14 17:38:42.403 4
CC3 2010-05-15 17:38:42.403 5
CC2 2010-05-16 17:38:42.403 6
CC1 2010-05-17 17:38:42.403 7
CC 2010-05-18 17:38:42.403 8
 b. ÄÇôÎÒÃÇɾ³ýRowNum ´óÓÚ5µÄ¼Ç¼
 
WITH UserEnrollWithRowNumber AS (
SELECT *, ROW_NUMBER() OVER(ORDER BY EnrollTime) AS
RowNum from [dbo].[UserEnroll])
DELETE from  UserEnrollWithRowNumber
WHERE RowNum >  5
½á¹ûΪ effect 3 rows
 c. ÔÙÓÃa²½ÖеÄÓï¾ä²éѯ±¨Ãû±í½á¹ûΪ
UserName EnrollTime RowNum
CC7 2010-0


Ïà¹ØÎĵµ£º

SQL SERVER¶¨Ê±×÷ÒµµÄÉèÖ÷½·¨

 Èç¹ûÔÚSQL Server ÀïÐèÒª¶¨Ê±»òÕßÿ¸ôÒ»¶Îʱ¼äÖ´ÐÐij¸ö´æ´¢¹ý³Ì»ò3200×Ö·ûÒÔÄÚµÄSQLÓï¾äʱ, ¿ÉÒÔÓùÜÀí->SQL Server´úÀí->×÷ÒµÀ´ÊµÏÖ¡£
¡¡¡¡1¡¢¹ÜÀí->SQL Server´úÀí->×÷Òµ(°´Êó±êÓÒ¼ü)->н¨×÷Òµ
¡¡¡¡2¡¢Ð½¨×÷ÒµÊôÐÔ(³£¹æ)->Ãû³Æ[×Ô¶¨Òå±¾´Î×÷ÒµµÄÃû³Æ]->ÆôÓõķ½¿òÄÚÊǹ´ºÅ->
·ÖÀà´¦¿ ......

ÐÂÊÖÈëÃÅ:SQL server2000°²×°Í¼½â

¡¡Microsoft SQL server2000ÓÉһϵÁÐÏ໥Э×÷µÄ×é¼þ¹¹³É¡£ÄÜÂú×ã×î´óµÄWEBÕ¾µãºÍÆóÒµÊý¾Ý´¦Àíϵͳ´æ´¢ºÍ·ÖÎöÊý¾ÝµÄÐèÒª¡£±¾ÎÄ´øÀ´µÄ¾ÍÊÇÔÚwindows»·¾³ÏÂSQL2000µÄ°²×°¹ý³Ì¡£
¡¡¡¡
¡¡¡¡ÏµÍ³ÐèÇó
¡¡¡¡
¡¡¡¡ÕâÀïÒÔÆäËĺÏÒ»°æ±¾ÎªÀý£¬ÒÔÏ°²×°¹ý³ÌͬÀí¡£Microsoft SQL Server 2000 ¿ÉÔÚÔËÐÐ Intel»ò¼æÈÝµÄ Pentium¡¢Pentium ......

SQL Server ϵͳ±í

sysforeignkeys
°üº¬¹ØÓÚ±í¶¨ÒåÖÐµÄ FOREIGN KEY Ô¼ÊøµÄÐÅÏ¢¡£¸Ã±í´æ´¢ÔÚÿ¸öÊý¾Ý¿âÖС£
ÁÐÃû Êý¾ÝÀàÐÍ ÃèÊö
constid  int  FOREIGN KEY Ô¼ÊøµÄ ID¡£
fkeyid  int  ¾ßÓÐ FOREIGN KEY Ô¼ÊøµÄ±í¶ÔÏó ID¡£
rkeyid  int  ÔÚ FOREIGN KEY Ô¼ÊøÖÐÒýÓõıí¶ÔÏó ID¡£
fkey  smallint ......

SQL server 2008 ÆóÒµ°æ

ºú»Ô£º13028803715       0755-82945017
9¡¢ÉîÛÚmicrosoft Windows 2003 Server±¨¼Û ÖÐÎıê×¼°æ5Óû§    4100
10¡¢ÉîÛÚmicrosoft Windws 2003 Server±¨¼Û ÖÐÎÄÆóÒµ°æ25Óû§   20500
11¡¢ÉîÛÚmicrosoft Windows 2008 Server±¨¼Û ÖÐÎıê×¼°æ5Óû§   580 ......

ÈçºÎÁ´½Óµ½Sql Server 2005


SQL Server 2005
±¾Æª½éÉÜÈçºÎÁ´½Óµ½Sql Server 2005.
²ÉÓÃSQL ±¾µØ¿Í»§ ODBCÇý¶¯
²ÉÓÃSqlÉí·ÝÑéÖ¤
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ÄãÕýÔÚʹÓÃSQL Server 2005 Express£¿±ðÍü¼ÇÁË£¬ServernameµÄÓï·¨ÊÇServername\SQLEXPRESS£¬Äã¿ÉÒÔÓÃÄã°²× ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ