Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the Default Column value in sql server

Tags:

sql

default

In my table while altering I gave '1' to the default. Now I need to reset the value for the default one, '0'. I tried the following script but it is throwing an error.

ALTER TABLE Order ADD Cancel BIT CONSTRAINT [DF_Order_Cancel] DEFAULT ((1)) NOT NULL;

Here I need to reset the default value to '0' instead of '1'.

I tried the script below but it's still throwing an error.

ALTER TABLE Order ADD DEFAULT (0) FOR Cancel
like image 681
RickyRam Avatar asked Dec 20 '22 10:12

RickyRam


1 Answers

First, delete the constraint.

alter table Order drop constraint DF_Order_Cancel

Then recreate it.

ALTER TABLE Order ADD DEFAULT 0 FOR Cancel

Edit: the following statements run fine.

ALTER TABLE Order ADD Cancel BIT CONSTRAINT [DF_Order_Cancel] DEFAULT ((1)) NOT NULL;
alter table Order drop constraint DF_Order_Cancel
ALTER TABLE Order ADD DEFAULT 0 FOR Cancel
like image 60
Francois Avatar answered Jan 13 '23 02:01

Francois