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
  • YouTube channel lists – Python working with files Python working with files
  • How to Generate Random Integers Between 0 and 9 Python
  • How to data cleanse a database table Python Data Cleansing
  • TypeError object of type ‘int’ has no len() Python
  • ValueError: pattern contains no capture groups Value Error
  • IndexError: list index out of range Index Error
  • Import a CSV file with an SQL query CSV
  • python sort method python method

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

  • how to create and drop a table in SQL SQL
  • How to use wildcards in SQL SQL
  • how to use case statements in SQL SQL
  • how to select columns with SQL SQL
  • How to Group By in a Select Statement SQL
  • How To Join Tables In SQL SQL

Leave a Reply Cancel reply

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

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • TypeError: ‘str’ object is not callable Python Functions
  • How to group your data in Tableau data visualisation
  • how to remove unwanted characters from your data R Programming
  • IndexError: single positional indexer is out-of-bounds Index Error
  • What is the r programming language R Programming
  • TypeError: ‘float’ object is not callable Python
  • Python Tutorial: Pandas groupby columns ( video 2) Python
  • How to use parameters in Python Python

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