Search code examples
sqlsql-serverincrementnavicat

How to make an incremented column that is not an id and can be copied in SQL Server


I have a table that has numerous records entered into it by hand. Through navicat that need to be able to be sorted by the order in which they were added. As of right now, I have an incrementing identity column called ID that is a primary key. But since it is the primary key, the column can not be copied and I get the error "field 'ID' can not be modified" every time I try to enter a new record. Can I have another data type that increments and can be duplicated? It doesn't matter if a few of them have the same ID value. I just need to have the records in general order of when they were added.

To add the id column originally I did this:

alter table accnt add ID int identity(1,1) not null

but I wanted for it not to be a primary key so I tried this with no luck:

alter table accnt add ID int numeric(1,1)

and

alter table accnt add ID int varchar(1,1)

all with no luck. how can I accomplish what I am trying to do?


Solution

  • Rather than inserting them in a particular order you should be thinking about using them in a particular order using a select statement. The order that the rows are held in a table when you add them are of little consequence to what you want to do. Your identity ID column can tell you what order they were added eg:

    Select ID
    FROM accnt
    ORDER BY ID ASC
    
    Select ID
    FROM accnt
    ORDER BY ID DESC