Maulwy:
Yes, it is unique and could function as a key, BUT:
1. If you already have a column such as TransactionDate in the table then
you are repeating the value of that by the first 8 digits of the structured
key. Consequently the table is open to inconsistent data as there is nothing
to stop the values in one or both of the two columns being amended
independently of each other. The design is thus a bad one.
2. If you don't have a separate TransactionDate column you are storing two
separate values in the structured key, the first being a value of attribute
type 'transaction date', the other being a value of attribute of type
'ordinal number per day'. The definition (taken from Chris Date) of First
Normal Form (1NF) is:
"A relvar is in 1NF if and only if, in every legal value of that relvar,
every tuple contains exactly one value for each attribute."
In the language of the relational model a relvar loosely equates to a table
definition, a tuple to a row, an attribute to a column. In your case the
'structured key' column would contain two values of different attribute types.
Not only is this a bad design in principle, therefore, but it would give rise
to the practical problem of having to derive a date value from the column
every time you need to know the transaction date.
By having two columns, one for the ordinal number per day (of integer number
data type) and another for the transaction date (of date time data type) then
both of the above objections are overcome. The primary key can be a
composite one of both columns, or you can use a surrogate primary key, e.g.
an autonumber, and uniquely index the other two columns (in combination, not
individually) as these constitute a 'candidate key'. The ordinal number per
day can be computed in the way Doug described.
Ken Sheridan
Stafford, England
Dear Bruce,
I may be reading this wrong or missing something, but I don't see the reason
for formatting the date in the Where condition. Not that it does any harm I
[quoted text clipped - 7 lines]
Format([RecordDate],"yyyymmdd") & Format([ID],"\-001")
Thank you for the answer.
I apologize for the less knowledge that I have. My basic thought is to
create ordinal numbers, which are build from the date of this order + the
transaction number, then this number will return from the beginning of the
next day. Eq: today we have 3 transaction, and the number is 20090716001,
20090716002, 20090716003. Next day, we have 2 transaction, and the number is
20090717001, 20090717002. Its arises and restart every day.
To the OP, note that a number created in this way will not be the primary
key field, as it is incrementing only the end of the number, so will restart
at 1 every day. An autonumber field could be used as the primary key
instead.
It's unique. Why can not be used as the primary key?
May have other suggestions?
Rgds,
Maulwy