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!

Recommended Answers

All 3 Replies

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.