Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 2008 ´´½¨Ö÷¼üΪ×ÔÔöÁеıí

ʹÓÃTranact-SQL ±àд´úÂëÀ´´´½¨Ò»¸öÐÂ±í£º
 
USE [OnlineJudge]
GO
/****** Object: Table [dbo].[User1] Script Date: 05/17/2010 14:05:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[User2](/*notice convert the tablename*/
[num] [int]IDENTITY(1,1) NOT N ......

SQL֮ʮ profiler

Microsoft SQL Server Profiler ÊÇ SQL ¸ú×ÙµÄͼÐÎÓû§½çÃ棬ÓÃÓÚ¼àÊÓ Êý¾Ý¿âÒýÇæ»ò Analysis Services µÄʵÀý¡£Äú¿ÉÒÔ²¶»ñÓйØÿ¸öʼþµÄÊý¾Ý²¢½«Æä±£´æµ½Îļþ»ò±íÖй©ÒÔºó·ÖÎö¡£ÀýÈ磬¿ÉÒÔ¶ÔÉú²ú»·¾³½øÐмàÊÓ£¬Á˽âÄÄЩ´æ´¢¹ý³ÌÓÉÓÚÖ´ÐÐËÙ¶ÈÌ«ÂýÓ°ÏìÁËÐÔÄÜ¡£
¿ÉÒÔʹÓà SQL Server ProfilerÀ´´´½¨Ä£°å£¬¶¨ÒåÒª°üº¬ÔÚ¸ú×ÙÖ ......

sqlÌæ»»Óï¾ä

--·Ö½â×Ö·û´®°üº¬µÄÐÅÏ¢ÖµºóÈ»ºóºÏ²¢µ½ÁíÍâÒ»±íµÄÐÅÏ¢
--(°®Ð¾õÂÞ.ع»ª(Ê®°ËÄê·çÓê,ÊصñùɽѩÁ«»¨¿ª)  2007-12-23  ¹ã¶«ÉîÛÚ)
/*ÎÊÌâÃèÊö
tba
ID  classid   name
1     1,2,3   Î÷·þ
2     2,3     ÖÐɽװ
3&n ......

SQL SERVER 2005 Ö»ÓÐmdfÎļþµÄÊý¾Ý»Ö¸´·½·¨


Ò»´ÎProjectÏîĿƽ̨(PWA)ÒâÍâÍ£»úÇÒÅäÖÃÊý¾Ý¿âSharePoint_Config µÄLDF±»ÒâÍâɾ³ý,Èç¹ûÖ±½Ó¸½¼ÓMDFÎļþÔòÎÞ·¨¸½¼Ó.
Ïȳ¢ÊÔsp_attach_single_file_db»Ö¸´,Ö´ÐÐÈçÏÂ:
sp_attach_single_file_db 'SharePoint_Config','D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\SharePoint_Config.mdf'
³öÏÖ´íÎóÌáʾ:
......

SQL Azure vs SQL Server

¹«¸æ£º±¾²©¿ÍΪ΢ÈíÔƼÆËãÖÐÎIJ©¿ÍµÄ¾µÏñ²©¿Í£¬²¢²»±£Ö¤Á´½Ó¿ÉÓÃÐÔ£¬ÎªÁ˱£Ö¤ÔĶÁÌåÑ飬Çë·ÃÎÊhttp://blogs.msdn.com/azchina¡£
 
 
SQL Azure vs. SQL Server
¸ÅÒª
SQL Azure Database ÊÇÒ»¸öÀ´×Ô΢ÈíµÄ£¬»ùÓÚÔƵĹØϵÐÍÊý¾Ý¿â·þÎñ¡£SQL Azure Ìṩ¹ØϵÐÍÊý¾Ý¿â¹¦ÄÜÀ´×÷Ϊ¹«Ó÷þÎñ¡£»ùÓÚÔƵÄÊý¾Ý¿â½â¾ö·½°¸ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ