Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Timestamping records automatically

Re: Timestamping records automatically

From: Arch <send.no_at_spam.net>
Date: Sun, 07 Oct 2007 18:16:55 -0400
Message-ID: <i6mig3dhie5vq6j6bjknc3sj8ef875tr05@4ax.com>


On Sat, 06 Oct 2007 00:16:53 -0700, DA Morgan <damorgan_at_psoug.org> wrote:

>Arch wrote:
>> I need to add a date / time stamp to records as they are inserted into
>> a table. I need to do this at the server end.
>>
>> Is there a "correct" way to do that? Should I simply use a default
>> value of sysdate? Or should this be done with a trigger or something
>> else?
>>
>> Thanks for any advice
>
>CREATE TABLE t (
>col1 VARCHAR2(20),
>col2 DATE DEFAULT SYSDATE);
>
>INSERT INTO t
>(col1)
>VALUES
>('AAA');
>
>SELECT * FROM t;
>
>Documented in Morgan's Library at www.psoug.org under HEAP TABLES.

I'd like to ask a follow up question if I may. If I wish to require that default sysdate value and not permit the user to override it, is a good approach to simply provide a view of the table without that field?

Borrowing from Daniel's example:

CREATE TABLE t (
col1 VARCHAR2(20),
col2 VARCHAR2(20),
col3 DATE DEFAULT SYSDATE) ;

CREATE VIEW v AS (
SELECT col1, col2
FROM t ) ;

GRANT SELECT, INSERT ON v TO userperson ;

Is this a good solution?

Again, thanks for any advice Received on Sun Oct 07 2007 - 17:16:55 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US