6

I am working with PostgreSQL database. I have created the required tables. Now I have to alter table columns as per constraints. I have to apply default constraint to one of my columns whose default value should be 1.

This is the query I am using,

ALTER TABLE Alerts ADD  CONSTRAINT DF_Alerts_bIsActive SET DEFAULT ((1)) FOR bIsActive;

This is the error I am Getting,

ERROR:  syntax error at or near "SET"
LINE 30: ... TABLE Alerts ADD  CONSTRAINT DF_Alerts_bIsActive SET DEFAUL...
                                                              ^
SQL state: 42601
Character: 948

Please can anyone suggest me the proper way to achieve this.

0

1 Answer 1

12

There is no such thing as a "default constraint". You simply define default values.

alter table alerts alter column bisactive set default 1;

Unrelated, but: bisactive sounds like that is some kind of flag. You should define that as a proper boolean column, not an integer.

Sign up to request clarification or add additional context in comments.

1 Comment

In fact interestingly enough in MS SQL Server there is such thing as default constraint, and the syntax in the question relates to that. Things are sometimes strange in MS world.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.