Change a Nullable column to NOT NULL with Default Value

后端 未结 5 702
臣服心动
臣服心动 2021-02-02 05:17

I came across an old table today with a datetime column called \'Created\' which allows nulls. Now, I\'d want to change this so that it is NOT NULL, and also include a constrai

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 05:41

    If its SQL Server you can do it on the column properties within design view

    Try this?:

    ALTER TABLE dbo.TableName 
      ADD CONSTRAINT DF_TableName_ColumnName
        DEFAULT '01/01/2000' FOR ColumnName
    

提交回复
热议问题