Insert an “insertion date” value into a SQL table automatically?

前端 未结 5 1456
旧巷少年郎
旧巷少年郎 2021-01-24 11:49

Is there a way to define a datetime column and populate it automatically when a row is inserted, without having to use a trigger?

The value would be the point in time w

相关标签:
5条回答
  • 2021-01-24 12:22

    Yes, use a default:

    create table test_table (d_col datetime default current_timestamp)
    
    0 讨论(0)
  • 2021-01-24 12:28

    create table FACT_LO ([LOAD_DATE] [datetime] default getdate())

    0 讨论(0)
  • 2021-01-24 12:29

    Very simple. When designing the table in SSMS, set the field's default value to getdate()

    0 讨论(0)
  • 2021-01-24 12:31

    Yes, use a default constraint of GetDate()

    0 讨论(0)
  • 2021-01-24 12:35

    Yes use a default constraint:

    mydatecolumn datetime 
        constraint DF_myDate DEFAULT (getdate())
    
    0 讨论(0)
提交回复
热议问题