0

Hi
I have a table with two columns (ID,ROW) I need to make the ID COLUMN unique and increase it value by 1 for each row.
-----------------------
ID ROW
1 NULL
1 NULL
1 NULL
1 NULL

How can I replace the each 1 with sequentially increased value?
to be 1 2 3 4?
Thanks in advance!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by apegram
0

There is some wiered solution I got in mind. See if it works.

alter table your_table add column tmpSno int identity(1,1)
Go
update your_table set ID = tmpSno 
Go
alter table your_table remove column tmpSno
Go

Get the idea, the syntax might need re-checking

Close this if it works.

0

Is this for orcale? I'm using MYSQL :)
any way this dose not make it.

It should be something like UPDATE table SET id = id + 1
the id + 1 should be something that make the value increase Sequentially

1

Is this for orcale? I'm using MYSQL :)
any way this dose not make it.

It should be something like UPDATE table SET id = id + 1
the id + 1 should be something that make the value increase Sequentially

That would be for SQL Server, as you asked your question on a SQL Server forum. The MySQL forum is here.

Instead of an IDENTITY field, MySQL has an auto-incremented integer that performs the same function. I doubt seriously that you'll be able to get your desired result with the desired method ("UPDATE table SET id = id + 1") without a stored procedure of some kind, and it will be particularly difficult if those are the only two fields you have in the table and there is nothing at all unique about each record. But that's just an assumption on my part.

Edited by apegram: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.