Abdul Moiz
Abdul Moiz

Reputation: 3

How do I rename a column which is referenced in a computed column in SQL Server?

I have a table with some computed columns. I want to be able to rename the columns which are referenced in these computed columns as well as rename the computed columns.

I have tried the following SQL commands:

Exec sp_rename 'tbl_1_PattFormulaTest6.SumOfNumbers123_calculation2', 'SumOfNumbers123_calculation2_edited', 'COLUMN'

I get this error message for trying to rename a referenced column:

Object cannot be renamed because the object participates in enforced dependencies.

So what's the proper way for renaming the columns referenced in the computed column and renaming the computed column itself?

Upvotes: 0

Views: 1530

Answers (1)

Sean Lange
Sean Lange

Reputation: 33581

The way to do this is three steps.

  1. Drop the computed column.
  2. Change the column name.
  3. Recreate the computed column with the new column name in the definition

Upvotes: 5

Related Questions