SQL Server change primary key to different [new] column and update foreign key references -


i have table model varchar primary key of alias.

i have table device , table error each have foreign key references model's primary key of alias.

what need add new column model serve new primary key (int indentity(1,1)), therefore making alias plain old column. means need update foreign key references in device , error reflect new primary key column in model.

the problem how messy business cleanly , in right order. can modify script use create db scratch no problem, messy part how update existing database.

i have limited knowledge of complex actions , rather continue spend next day or 2 figuring out how right way , possibly borking db few times, i'd rather right first time.

  1. add identity column model.
  2. add new fk columns device , error.
  3. update device , error, setting new fk columns value of model's new pk, old fk = old pk (alias).
  4. drop old fk columns device , error

Comments