none
Default Value or binding column property

    Question

  • Hi all,

    Is it possible to set column property "Default Value or Binding" to an another column of the table?

    Thank you
    Evgeniya
    • Moved by Tom PhillipsModerator Tuesday, March 09, 2010 2:24 PM Possibly better answer from TSQL forum (From:SQL Server Database Engine)
    Tuesday, March 09, 2010 10:56 AM

All replies

  • Hi,

    You can try following

    Create Table Test
    (
    ColumnName int identity ,
    DefaultValuedateColumn datetime default getdate() ,
    Defaultvalueintcolumn int default 100 ,
    DefaultBinColumn as Defaultvalueintcolumn
    )


    Failure in Life is failure to try...
    Tuesday, March 09, 2010 11:09 AM
  • This can be done as below

    ALTER

     

     

     TABLE dbo.tablename ADD CONSTRAINT DF_Table_1_address
    DEFAULT N'default value' FOR column name

     



    Check in BOL
    ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/f1745145-182d-4301-a334-18f799d361d1.htm

    Hope this help
    Mohd Sufian www.sqlship.wordpress.com Please mark the post as Answered if it helped.
    Tuesday, March 09, 2010 11:21 AM
  • Maybe i have explained incorrect.

    In this case

    Create Table Test
    (
    ColumnName int identity ,
    DefaultValuedateColumn datetime default getdate() , - is default value = getdate() - 1
    Defaultvalueintcolumn int default 100 , - is default value 100 - 2
    DefaultBinColumn as Defaultvalueintcolumn - is computed column - 3
    )

    But i need another property:
    There is a table Table1.
    There are 2 columns in the Table1:
    Column1 datetime,
    Column2 - if the user leaves the column blank, Value of the Column1 will be inserted into the column; but it is not computed column because the user are able to change the value in the Column2 independent of the Column1

    Thank you
    Evgeniya
    Tuesday, March 09, 2010 11:40 AM
  • Are u doing the insert using a stored procedure or directly from the application


    Mohd Sufian www.sqlship.wordpress.com Please mark the post as Answered if it helped.
    Tuesday, March 09, 2010 12:17 PM
  • directly from the application, actualy from SSIS

    Tuesday, March 09, 2010 12:20 PM
  • Hi,

    Another way is to create a insert & update trigger for your table, if you have checked the null value in column2, you can assign it with the value in column2.

    Besides, you mentioned SSIS, is the tables imported from another table in SSIS data flow? If so, you can add a data processing step between source and destination, check the column2 in that step.

    Thanks.
    Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 12, 2010 2:12 AM