Monday, October 4, 2021

Add the default value of the datetime field in SQL server

It is very common requirement while development that in SQL Server we have to insert current date and time on particular column like Record Created Date.

To fullfill this kind of requirement, there is a provision in SQL Server i.e. Default Value or Binding property, if we use this property then we dont need to provide date time value explicitly while inserting the record.

This can also be done through the SSMS GUI.

  1. Put your table in design view (Right click on table in object explorer->Design)
  2. Add a column to the table (or click on the column you want to update if it already exists)
  3. In Column Properties, enter (getdate()) in Default Value or Binding field as pictured below

Image of table in design view

No comments:

Post a Comment

QueryExpression vs. FetchXML in MS CRM with C#

Microsoft Dynamics CRM (Customer Relationship Management) is a powerful platform that helps organizations streamline their business processe...