Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2008

    Unanswered: adding a column with default NULL

    Hello Gurus,

    One quick question.

    How to define a column to accept null values in db2? I guess columns accept null values when it is created.

    Also is there any specific syntax to define a column with default null, also is there any difference in syntax if db2 is residing on windows and mainframe?

    ALTER TABLE SchemaName.TableName ADD ColumnName DataType WITH DEFAULT NULL

    The above command works fine when executed in DB2 on Windows.

    Please let me know whether above syntax will work fine on DB2 in Mainframe OS (Z/OS)
    Please revert back at the earliest.

    Thanks and Regards,
    Priyesh V Pande

  2. #2
    Join Date
    Dec 2008
    This is the format for adding a nullable column:

    alter table schemaname.tablename add column columnname integer;

    This is true for DB2 on all platforms. By adding WITH DEFAULT, you are giving the column a default value: an empty string for CHAR columns, 0 for numeric columns, current date or time or timestamp for date/time columns, etc.. The default value will be used instead of null if a row is inserted without providing a value for the column.

  3. #3
    Join Date
    Jan 2007
    Jena, Germany
    If you don't specify a WITH DEFAULT clause, then DB2 will implicitly use WITH DEFAULT NULL as default.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts