java123999 java123999 - 2 months ago 26
SQL Question

Adding a column with a Default value?

I am adding a column to my database table. It is a simple Char column with either a value of 'Y' or 'N'.

Is it possible to default the column to be 'N'? If so, how?

Current Script to add column:

ALTER TABLE PERSON
ADD IS_ACTIVE VARCHAR2(1);

Answer
ALTER TABLE PERSON
ADD IS_ACTIVE VARCHAR2(1) DEFAULT 'N'

If you want, you can add a NOT NULL constraint:

ALTER TABLE PERSON
ADD IS_ACTIVE VARCHAR2(1) DEFAULT 'N' NOT NULL