Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Timestamp field as primary key

190237Feb 12 2003 — edited Feb 12 2003
Hello,

I am dealing with a "log" table to record accesses by end users to different objects. Information to be recorded is user_id, access_time and object_id. Even if it is not really needed, I would like to define a primary key for this table.

Before knowing about the timestamp datatype in Oracle 9i I was thinking on using a sequence to get the value for the log_id field (PK). Now that I have seen how timestamp and systimestamp work I am wondering about the convenience of declaring the PK on the access_time field, timestamp datatype and systimestamp as default value.

The DDL for this table would look like:

create table log (
access_time timestamp default systimestamp,
user_id varchar2(15) not null,
object_id varchar2(15) not null,
constraint log_pk primary key (access_time)
);

The insert DML would be then something like:

insert into log (user_id, object_id) values ('user1', 'object1');

The question is about the convenience of declaring the PK on the timestamp field. Is that OK or would it be preferable (safest) to use the sequence for the PK?

Thanks in advance,

Manuel
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2003
Added on Feb 12 2003
3 comments
1,039 views