Thursday, September 25, 2008

SQL Server 2005 : Generate Sequence number and delete rows with top

Generate Sequence Number in SQL 2005

Select ROW_NUMBER() OVER(ORDER BY Column_Name) As ID,* From Table_Name



Delete First Row in SQL 2005

WITH T1 AS (Select Id,FirstName,LastName, ROW_NUMBER()
OVER (PARTITION BY Id,FirstName,LastName Order By Id) AS NUMBER From TEMP)
Delete From T1 Where Number > 1



The Most easiest way to delete first row in SQL 2005 is,


Delete top (1) From Table_Name

No comments: