The Object 'XXXX' is dependent on column 'XXXX'

Asked

Viewed 223 times

2

When I try to change the type of the primary key of a table, I get the following error:

The object 'XXXX' is dependent on column 'XXXX'.

I would like to know how to "less" manual fix this error without having to disable the dependencies one by one.

1 answer

0

The answer as follows is wrong:

-- Desabilita constraints de todas as tabelas
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

-- Reabilita constraints de todas as tabelas
EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'

In accordance with: Stackoverflow (in English) and Sqlauthority (in english)

But attention, your tables will be unmanned until rehabilitation of the same.

In production environments, use sparingly.

Primary keys cannot be disabled, need to be droppings/removed. 3

Already considering the added requirement in the commentary, about keeping state.

Algorithmically speaking, your exit would be something like: `

Salva estado atual -> Dropa todas as constraints -> Retorna o estado atual

Perhaps the best solution is export their constraints/retributions, with the Generate Scripts Wizard , or script, and then drop them, importing again completed the task.

Later I will think of something programmatic, nothing safe for a long-standing realistic production environment, but perhaps for normalized relational models and on certain considerations such as simple keys.

  • 1

    There is no risk of enabling a CONSTRAINT that was already disabled for some other reason when you enable all later?

  • Ah, for sure!

  • Can you formulate a safer answer then?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.