Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Check constraint question
Tue, Feb 24 2009 2:20 PMPermanent Link

Darrell
Is there a way to have a timestamp field default to

(pseudo code)

IF FIELD = NULL THEN FIELD = CURRENT-TIMESTAMP

via check constraint?
Tue, Feb 24 2009 11:34 PMPermanent Link

Richard Harding
Darrell,

A check constraint will generate an error if the condition is not met.   It will not cause
anything to be set.

The TRIGGER below will do what you want.  You will need another BEFORE INSERT TRIGGER
also.  Would setting a DEFAULT VALUE of CURRENT_TIMESTAMP for the field be a benefit?


CREATE TRIGGER "BeforeUpdate" BEFORE UPDATE ON "aTable"
WHEN OLDROW.EpisodeDateTime is Null
BEGIN  
  SET NEWROW.EpisodeDateTime = CURRENT_TIMESTAMP;
END;

Richard Harding
Wed, Feb 25 2009 12:27 AMPermanent Link

darrell
Thanks Richard - exactly what i was looking for
Wed, Feb 25 2009 6:03 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Darrel

As Richard said, you can't do it using check constraints.
You can do it using triggers or simply defining a default value for the
column:

ALTER TABLE <TableName>
 ALTER COLUMN <ColumnName> AS TIMESTAMP DEFAULT CURRENT_TIMESTAMP

You can also define default values for columns interactively, using
EDBManager.

--
Fernando Dias
[Team Elevate]

Image