SQL – Getdate

Marketing
Marketing
  • Updated

By David Crowther

SQL___Getdate_-_1.PNG

Question:

How can I automatically insert the date into records in my SQL table?

Answer:

You may have a GIS Layer e.g. Planning Applications that are stored as a Table in a SQL database. Each time a new record (Planning App) is inserted into that table you would like today’s date adding into a Date Created field.

In our example we have a Planning App layer in our webGIS - MapThat.

SQL___Getdate_-_2.PNG

Before we insert a new record into the Planning Apps layer, we will edit the SCHEMA of our SQL Table to. To do this, select the table via SSMS > right click and choose DESIGN.

SQL___Getdate_-_3.PNG

  • Add a Date_Created Field – Type Date.
  • Using a Default Value – of Todays Date by using the text – getdate()

SQL___Getdate_-_4.PNG

Close and Save the changes to the Table Schema.

Now using MapThat (or QGIS), when a user adds a new record into the layer (Planning App)…

SQL___Getdate_-_5.PNG

….. once the new record has been inserted, the new field Date_Created will automatically be updated with today’s date by using the default value of getdate().

SQL___Getdate_-_6.PNG

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.