Estimated reading time: 2 minutes
Below we will take you through the steps of how to complete this in SQL server management studio.
In this table we have created a new column called “date_created”
alter table dbo.CUSTOMER add constraint df_TABLE_DATE default getdate() for date_created
Note that the existing values will not change as I applied this update after the column creation.
Adding in a new record and checking that date stamp has been created
Using the below code:
Insert INTO dbo.CUSTOMER(CUSTOMER_NO,customer_type) VALUES (777777,'web')
Yields the following result:
As can be seen now for the new record, the date has been added.
It is probably good, that when designing the database table, that this is factored in from the very start , otherwise you will have to go back and change lots of records, which will be very time consuming.