-1

I am using Sql Server for Visual Studio. I Have two columns, 1 is auto-incremented and the other is not but I want make the both primary keys and the unincremented key can be used as a foreign key in another table. thanks

Chris
  • 243
  • 3
  • 10

1 Answers1

3

Like TomTom said, what are you trying to do has no sense. If the second column (the one you are calling unincremented) is already unique, you can drop the auto-increment column because it's redundant and useless.

The redundancy is caused by the fact that 2 unique columns, aggregated in one single key, not only compromises the uniqueness of the columns themselves, but it uses 2 different columns to describe the same values!

  id   |   col   |  some_data
-------------------------------
   1   |    A    |
   2   |    B    |
   3   |    D    |

As you can see, if i want to point to a specific row, in this case you're describing, I can just use id or col columns and both of them are valid!

If instead, the unincremented column is not unique, the primary key should only be the auto-incremented column and this one should be used as foreign key in other tables.

The last option you have, if you really want to have 2 distinct columns, is to not set the first one as auto-increment column.

As a general rule auto-increment columns should always be used as a single-column key.

mordack550
  • 492
  • 4
  • 14