How to add a default Constraint to an already created column in SQL Server?

Asked

Viewed 2,771 times

1

In SQL Server, assuming the column already exists, how to create a new DEFAULT Filter? I looked in various references and in all the examples, always had the column to create together. I found the question interesting and would like to integrate it the knowledge base of Sopt.

1 answer

1


The command is:

ALTER TABLE [schema].[tabela] 
  ADD  DEFAULT (([valor])) FOR [coluna]

If you prefer to name the Constraint:

ALTER TABLE [schema].[tabela]
  ADD CONSTRAINT [nome-da-constraint] DEFAULT [valor-padrao] FOR [coluna] 

He even enriched the article also indicating how to delete only the Constraint.

alter table [schema]. [table] drop Constraint [name-of-Constraint]

I found the answer in one of Soen

Browser other questions tagged

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