Tuesday, November 5, 2024

Using Your Database To Do the Work

A lot of people have asked me “what can I do to make the database work for me, instead of ColdFusion?”. The truth is that any veteran developer will tell you that making the database do the work, is the best practice in web development. I can think of a few different ways to make the database work for you. By this I mean telling the database to insert values, create tables and much more. In this tutorial I will show you the basics of how to make your database do the work for you! let’s begin.

In this example we will be using an access database to have the current date and time be automatically inserted, when a new record comes in. Traditionally you had to have ColdFusion insert the date with the command #CREATEODBCDateTime#, but making the database do the work is much faster and way more reliable. Let’s show you how it’s done..

The first thing you will need is a date/time field in your table. call this field:
PostDateTime

Set the value of the field to be Date/Time (for more see picture below).

Notice that the field is called PostDateTime and the data type is set to Date/Time. The next thing we need to do is tell this field to automatically place the current date/time when a new record is inserted into the database, to achieve this you simply make the following addition to this field:

Notice that in the default value, I simply added the command Now(), this let’s the database know that when a record is inserted that it should automatically add the current date/time. Let’s see the end result within the database.

Notice that even though there isn’t a value in “Name”, the date time field is automatically there. If you close and reopen the table, the date changes to the current date. So when a record is inserted it keeps that date and you can therefore use it to display on your page with the DateFormat and TimeFormat functions.

This is just a simple way of making the database do the work for you, instead of making ColdFusion (or whatever other language you use) do extra work to achieve the same result.

Congratulations, you now know how to make the database do the work, instead of your development language.

*Originally published at EasyCFM.com

Click Here to sign up for FREE Tech. Newsletters from murdok!

EasyCFM.Com introduces at least three new tutorials each week, written by the webmaster (Pablo Varando) and also from individual people who post their own tutorials for visitors to learn from. For more information please visit: http://www.easycfm.com [EasyCFM is Hosted by Colony One On-Line – http://www.colony1.net]

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

Preventing and treating plant leaf scorch tip burn.