SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add Sequence number to existing table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ugh3012
Yak Posting Veteran

59 Posts

Posted - 11/14/2013 :  14:07:02  Show Profile  Reply with Quote
I have a table with no sequence column. I created a new column, but I need a way to add sequence number. This is not going to be a Primary key or indexed.

I assume I will use update, but how do I do this?


Example

Before
Name   | Seq
Paul   | NULL
Tom    | NULL
Grant  | NULL

After
Name   | Seq
Paul   | 1
Tom    | 2
Grant  | 3

Edited by - ugh3012 on 11/14/2013 14:08:57

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 11/14/2013 :  14:28:25  Show Profile  Reply with Quote

UPDATE t
SET Seq = Rn
FROM 
(
SELECT Seq,ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS Rn
FROM Table
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000