Home > Software design >  Adding a boolean coulmn into existing table of oracle database
Adding a boolean coulmn into existing table of oracle database

Time:10-07

I am using oracle database and I have a table named MyTitle and into this existing table I have to add a column of type boolean so the name of the column is IsChecked and the default value should be false of that column, I have tried the below way please advise is it correct or not

alter Table MyTitle add IsChecked Number(1) default 0 not null ;

CodePudding user response:

It looks reasonable. Do you have a problem with it? Different people/ systems have different conventions for pseudo-boolean columns. Some use a number with 0 and 1. Some use a char(1) with a 'Y' and 'N'. Be consistent with whatever convention exists in your system.

I'd normally include a check constraint that limits the values in the column to the values you want, i.e.

check( isChecked in (0,1) )

If you're building a data warehouse, though, there are schools of thought that including check constraints like this is unnecessary overhead since there is (or should be) only a very small number of paths (ideally one) to load the data via the ETL process so you merely need to ensure that the ETL process isn't inserting invalid values.

  • Related