Add column with default value

  • I have table with 5 columns. Table have data. I need to add column ( column type bit). Column must not have null values, and i dont want to update table after adding column.

    Pleasa help .

    Thanks !

    Nevlad

  • Can u try it for the following way:

    Ex:

    create

    table t

    (

    id int not null

    ,

    col1 varchar (30) not null default ''

    ,

    col2 varchar (30) not null default ''

    )

    go

    insert

    into t

    select

    1, 'abc', 'xyz'

    union

    select

    2, 'xxx', 'abc'

    union

    select

    3, 'hai', 'bye'

    go

    select

    * from t

    go

    alter

    table t add col3 bit not null default 0

    go

    Kishore.P

  • Thanks. I found very easy way to solve the problem.

    ALTER TABLE ADD COL_NAME bit NOT NULL DEFAULT '1'

    Thaks again

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply