Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • What is data profiling and its benefits? data profiling
  • What are Lambda functions in Python? Python
  • TypeError: ‘NoneType’ object is not iterable class
  • How to Pass a Javascript Variable to Python using JSON Flask
  • How to Create Multiple XML Files From Excel With Python Python
  • supervised machine learning vs unsupervised machine learning? machine learning
  • how to remove unwanted characters from your data R Programming
  • What does the … operator do in Julia? julia

How to add a date when a record is created

Posted on May 13, 2021October 31, 2022 By admin No Comments on How to add a date when a record is created

Estimated reading time: 2 minutes

You maybe working with a lot of data and inserting it into tables, and want to create a date stamp so you can see when the record was created.

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”

We have altered this column to allow automatic date stamp creation as follows:

alter table dbo.CUSTOMER 
add constraint df_TABLE_DATE default getdate() for date_created

What the above code does is basically tell the database any time a new record is created, it should automatically add in a date to the column.

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.

SQL Tags:add contraint, alter a table, date, getdate(), SQL insert, timestamp

Post navigation

Previous Post: Import a CSV file with an SQL query
Next Post: What are dimensions in Tableau?

Related Posts

  • ValueError: cannot convert float NaN to integer Null values
  • how to insert data into a table in SQL SQL
  • What is Apache Spark and what is it used for? Apache Spark
  • How to use wildcards in SQL SQL
  • how to select columns with SQL SQL
  • how to use case statements in SQL SQL

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • YouTube channel lists – Tuples Python Tuples
  • What is Julia used for? Julia programming
  • Python Tutorial: Add a column to a data frame Python Dataframe
  • How To Compare CSV Files for Differences CSV
  • Python Tutorial: How to validate data using tuples Python Tuples
  • Python Dictionary Interview Questions Python
  • how to select all records with SQL SQL
  • How to delete a key from a Python dictionary Python

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme