Wednesday, October 18, 2017

Renaming Primary key and references in all tables sql server

Use sp_fkeys procedure to get all foreign keys

EXEC sp_fkeys 'Students', 'Academics'

Use nimble text to update keys

UPDATE $5.$6
SET $7 = $1.$2.$3
FROM $5.$6
INNER JOIN $1.$2 on $5.$6.$7 =  $1.$2.$3