Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Deletar CONSTRAINT


Question

Esse select retorna o valor que quero so preciso coloca-lo em em uma formula para ficar automático o drop da constraint.

select 'alter table' + QUOTENAME(OBJECT_NAME(c.parent_object_id))

+' DROP CONSTRAINT ' + QUOTENAME(c.name) from sys.default_constraints c

where c.name like 'DF__fatur_dev__Cod_C%'

Esse select me retorna esse valor abaixo, preciso colocar ele para executar automatico tipo tenho varios bancos para acertar isso então preciso de algo que execute o select e pegue o resultado e drop a constraint.

alter table [fatur_devolucao_prod] DROP CONSTRAINT [DF__fatur_dev__Cod_C__444B1483]

Tem como Galera? Desde já obrigado.

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Bom dia Fagner,

Para a sintaxe ficar dinâmica, você deverá:

- criar uma variável

- inserir o script

- executar a partir da variável.

Ex.:

DECLARE @String VARCHAR(100)
DECLARE @Variavel VARCHAR(10)

SET @Variavel = 'top 10 '

SET @String = 'select ' + @Variavel + ' * from sysobjects'

EXEC (@String)

Link to post
Share on other sites
  • 0

DECLARE @String VARCHAR(200)

DECLARE @Variavel VARCHAR(10)

SET @Variavel = 'top 10 '

select @String =

'alter table' + QUOTENAME(OBJECT_NAME(c.parent_object_id))

+' DROP CONSTRAINT ' + QUOTENAME(c.name) from sys.default_constraints c

where c.name like 'DF__fatur_dev__Cod_C%'

EXEC (@String)

Funfou, muito obrigado...abraço.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148865
    • Total Posts
      644863
×
×
  • Create New...