You want to make sure each order-id is unique since two orders with the same id-code is going to cause problems.
Either use the UNIQUE modifier on the field when defining the table ref, or create a UNIQUE index on that field (or fields) after the table is created ref.
It is customary to make sure there is a unique code for each record in a table (a primary key) so you can select that record and no other. If you don't know why this is a good idea, search the web for terms like "Normalisation" and "Normal forms".
When creating a table all the following fields will be forced to be unique.
CREATE TABLE foo ( field1 serial field2 text UNIQUE field3 text PRIMARY KEY field4 text, field5 text PRIMARY KEY (field4) ); CREATE UNIQUE INDEX foo_field5_idx ON foo(field5); |
The serial type creates a UNIQUE NOT NULL int4 and attaches it to a sequence.
The UNIQUE modifier creates a unique index on the value. You might want to add NOT NULL as well if the field should always have a value.
The PRIMARY KEY is equivalent to UNIQUE NOT NULL.
Which form you want to use will depend upon context and your personal preferences.