I would like to add a column to an existing table, where the new column would only have running numbers starting from 1. If I've understood correctly, the "create index" command is not the right way to do this, as that's attached to just certain columns to speed up querying.

The reason why I want this is that after exporting the data from the database I would still need to know the order of the rows.

Create Table TestTable
(
  SomeInt int,
  SomeString varchar(10)
)

GO
--This adds an auto number column
Alter Table TestTable Add RowNumber int identity(1, 1)
Create Table TestTable
(
  SomeInt int,
  SomeString varchar(10)
)

GO
--This adds an auto number column
Alter Table TestTable Add RowNumber int identity(1, 1)

Thanks! That did the trick! :)

You're welcome.

Please mark this thread as solved an good luck!

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.