Doubt with DROP command COLUMN sql server

0

I tried to delete a column from a database, I noticed that there are restrictions.

ALTER TABLE dbo.TB_ESTRACAO DROP COLUMN MULTIPLIER

I get a message, how can I resolve this? Thanks!

  

Message 5074, Level 16, State 1, Line 1   The object 'DF_TB_ESTRACAO_MULTIPLICADOR' is dependent on column 'MULTIPLIER'.   Message 4922, Level 16, State 9, Line 1   ALTER TABLE DROP COLUMN MULTIPLIER failed because one or more objects access this column.

    
asked by anonymous 24.07.2016 / 01:48

2 answers

0

The message indicates that a constraint with a default value was created for the column we are trying to delete. Before deleting this column, the constraint should be deleted.

ALTER TABLE TB_ESTRACAO DROP CONSTRAINT DF_TB_ESTRACAO_MULTIPLICADOR

Next we can delete the column:

ALTER TABLE TB_ESTRACAO DROP COLUMN MULTIPLIER

    
25.07.2016 / 18:03
1

The error message says that the object DF_TB_ESTRACAO_MULTIPLICADOR references the dbo.TB_ESTRACAO.MULTIPLICADOR column and therefore you can not delete it.

The following queries can help you understand who depends on whom:

Looking for objects that depend on the column:

SELECT
    OBJECT_NAME(OBJECT_ID),definition
FROM
    sys.sql_modules
WHERE
    definition LIKE '%MULTIPLICADOR%'

Searching Stored Procedures that depend on the column:

SELECT
    DISTINCT OBJECT_NAME(OBJECT_ID),
    object_definition(OBJECT_ID)
FROM
    sys.Procedures
WHERE
    object_definition(OBJECT_ID) LIKE '%MULTIPLICADOR%'

I hope I have helped!

    
24.07.2016 / 04:51