Delete Constraint after taking its name

Asked

Viewed 63 times

0

I’m spinning the next query to obtain the name of 2 constraints:

select TC.Constraint_Name from information_schema.table_constraints TC
inner join information_schema.constraint_column_usage CC on TC.Constraint_Name = CC.Constraint_Name
where TC.constraint_type = 'Unique' and CC.TABLE_NAME = 'NAVIO'
order by TC.Constraint_Name

How can I make a function to delete each value that returns in this select ?

  • you want to delete the return, is that it? would be the case to just delete instead of select?

  • That, I want to delete. The problem is that as I do not know the precise return of select. In the case there is a Constraint. To be more clear, I will always have 1 result in the return so I need to delete the Constraint whose name is the return of the query.

1 answer

0

Hello,

Follow an alternative to your case.

select 'ALTER TABLE ' + CC.TABLE_NAME + '  DROP [CONSTRAINT] '+ TC.Constraint_Name+' ; GO' 
  from information_schema.table_constraints TC
 inner join information_schema.constraint_column_usage CC on TC.Constraint_Name = CC.Constraint_Name
 where TC.constraint_type = 'Unique' and CC.TABLE_NAME = 'NAVIO'
 order by TC.Constraint_Name

See if it helps you, anything, just get back to me. With the return you will have the "DROP" of the contraints

Browser other questions tagged

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