How to Change Primary Key Column Name in a Table with Spatial Index

Here is a list of steps for how modify a column (primary key) name with spatial index for geography data type.

--step 0  Optional
--drop  foreign keys if pointing to the primary key column in question

---Step 1 drop spatial index
 --Step 2 drop primary key constraint

 --Step 4:  add primary key constraint
--Step 3 rename column name
 sp_rename @objname = N'[dbo].[myTablewithSpatialIndexForDatatype_geography_Column].[myOldID]', @newname = N'myNewId'  

  ---Step 5: add back SPATIAL INDEX

  ---Step 6:  add foreign key back to point to the primary key after name change 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s