Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autoincrement uniqueness after resetting 1

Status
Not open for further replies.

kstart

Programmer
Dec 25, 2004
21
US
I have a table called "report" and I am trying to reset the autoincrement value for the coming of a new year I did get some valuable advice from the forum so I made this statement;
ALTER TABLE REPORT ALTER COLUMN report_num i AUTOINC NEXTVALUE 1 STEP 1

and for all my work I got this error;
Command cannot be issued on a table with cursors in table buffering mode.

It should be simple to overcome but I am lost. I also don't think if I fix the problem it will matter as this is a primary key on the table and it would start over violating the uniqueness of the values.

Would the prefix 2004 help stop this from happening because in 2005 it would be report number 2005-1 vs 2004-1.

I am sure there is an easier way to generate year based report numbers but I have looked high and low to no avail.

 
HI

I suggest you dont use 2005-1. The character '-' in the id will not be acceptable for an integer field.
However, you can number with the first two digits representing the year. For example..

0500000001 for year 05. This will be an acceptable number and also makes the number unique.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Kstart,

The simple answer is not to buffer the table.

At the point where you want to reset the key, do this:

USE IN SELECT("report") && close table if already open
USE Report in 0 EXCLUSIVE && open the table for exclusive use
ALTER TABLE .... && as in your existing code
USE IN Report && close the table and carry on as before

I mentioned in your other thread that you cannot use dashes in the generated ID. Autoincs are purely integers in VFP. Just use a pure number, as Ramani suggested.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-consult.com)
 
Thanks again everyone and yes I just put the dashes in to illustrate the date not to include it in the number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top