ALTER TABLE DROP COLUMN failed because one or more objects access this column

前端 未结 7 1626
[愿得一人]
[愿得一人] 2020-12-05 22:26

I am trying to do this:

ALTER TABLE CompanyTransactions DROP COLUMN Created

But I get this:

Msg 5074, Level 16, Stat

7条回答
  •  被撕碎了的回忆
    2020-12-05 23:04

    As already written in answers you need to drop constraints (created automatically by sql) related to all columns that you are trying to delete.

    Perform followings steps to do the needful.

    1. Get Name of all Constraints using sp_helpconstraint which is a system stored procedure utility - execute following exec sp_helpconstraint ''
    2. Once you get the name of the constraint then copy that constraint name and execute next statement i.e alter table drop constraint (It'll be something like this only or similar format)
    3. Once you delete the constraint then you can delete 1 or more columns by using conventional method i.e Alter table Drop column column1, column2 etc

提交回复
热议问题