Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • Contact
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • how to select columns with SQL SQL
  • How to save data frame changes to a file Python Dataframe
  • how to add sine and cosine in python code numpy
  • What does the … operator do in Julia? julia
  • ValueError: invalid literal for int() with base 10 Value Error
  • Free ways to Extract Data from Files Livestream
  • How can I filter my data in Tableau? data visualisation
  • What is an Algorithm? machine learning

How to add a date when a record is created

Posted on May 13, 2021October 31, 2022 By admin

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

  • What is a CTE in SQL? SQL
  • how to insert data into a table in SQL SQL
  • Deleting table records with SQL SQL
  • how to write subqueries in SQL SQL
  • how to create and drop a table in SQL SQL
  • What is a Clustered Index in SQL? SQL

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • Deutsch
  • How To Add Values to a Python Dictionary Python
  • What is Jupyter notebook? Jupyter Notebook
  • Python Tutorial: Pandas groupby columns ( video 2) Python
  • How to run Python directly from Javascript Flask
  • What is Julia used for? Julia programming
  • python sort method python method
  • What are the built-in exceptions in Julia? Julia programming
  • How To Compare CSV Files for Differences CSV

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT