SEQNO is stored in table header, each time it is called it returns the next number, a zap of the table will reset the SEQNO to 0.
SYNCNUM is used internally and is uniquely assigned, it is not effected by zap and will continue to increase.
Also SEQNO is a numeric, SYNCNUM is a hexadecimal returned as a character.



Q:
I have added a field cpk_dsighting which is a C6 field. I want to mark this as the tables primary key.
A:
There is an automatically generated sequence number which uniquely identifies each row, you can return this using the SYNCNUM() function.
You could also create column with autoinc specified. If this is not on a form you would have to create the index yourself and set the order to it.
If you set your cpk_dsighting field to be the search field it will be master index tag order when you open that page, in addition Lianja will automatically build the index.



Q:
reset autoincriment column
A:
If you only have one autoinc column in the table, instead of the autoinc you could use seqno() as the default for the field (that's for numeric/int width 10, for a character field use strzero(seqno()) for 0000000001, 0000000002 etc., use strzero(seqno(),5) for 00001, 00002 etc.). Seqno() is automatically reset by the zap command. There's also a set seqno command to set it to a specific value.
Seqno() is available for Lianja native tables only and is table-based, increasing each time it is called.
Note that if you do want to keep the ids, delete + pack does not reset the seqno() value
As far as I know, none of the southwind sample tables have Auto increment or a seqno() Default set.
You would just need to uncheck Auto increment for your ID fields and set the Default to seqno(). You wouldn't need to change your sections or queries.



With the table open in the Lianja/VFP Command Window in the Console Workspace, you could even use the set seqno command so that it carries on from the last auto incremented number used:
Code:
// last rosterid used = 784
set seqno to 784
// next rosterid will be 785
If you want to continue with Auto increment then you need to drop and reset the constraint using alter table.



I don't think the syncnum has been set at that point and it is automatically applied to the row, so you can get it without it being in an actual field. If you just want an ID, you can use strzero(seqno()) - that will give you 0000000001, 0000000002 etc. Seqno is table-based, each time it is called the number is increased by 1. There are options to reset the current number and a ZAP sets it to 0.



Uniqueness is better checked at the database engine level as Hank mentioned.
In high transaction systems with thousands of users it will prevent duplicates at the time of the update using row level locking.
Any validation done in the UI for uniqueness could be correct when the validation is evaluated but incorrect at the time the data is committed on the server.
Autoinc fields and/or the use of the seqno() can be used to guarantee uniqueness also as these are atomic operations.
When using auto generated fields it is better to mark them as readonly in form and grid sections.



​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352