Re: Autoincremental field in VFP7

Tech-Archive recommends: Fix windows errors by optimizing your registry



The example to check out is

C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 9\SAMPLES\SOLUTION\DB\NEWID.DBC
and the table 'Ids' (table Char(10), id Integer)
For real use the width of the Table column should be much more, and there
should be a Candidste index instead of the Regular. index.


-Anders


"Barley Man" <BarleyMan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B391E234-83E8-4EF1-B15F-E835B6E9D1FA@xxxxxxxxxxxxxxxx
I think I can make sense of it now.

For your interest, or for anyone else reading this; the examples in the
TasTrade called 'NewId' produce a textual entry (letters, not numbers) and
thus it's no use when you are 'lost' as how to use it to increment a
numeric
feild, as I was!

With Craig's example, you shoiuld notice that I couldn't make it work as
written. Firstly, you MUST use capital letters (upper) as the name of the
table held within the Keys table (or else it create new entries in the
Keys
table ITSELF!) and that getkey() MUST be issued as getkey(tablename) where
'tablename' is the name of the table into which you are inserting the new
records!

Thanks guys, I think I am getting there in the end!

Ian
"Anders Altberg" wrote:

Sorry Ian
I made a gross mistake and pointed you to CREATE TRIGGER ON INSERT
..command.
Altogether wrong. That would create a table validation rule that would
check
if the insert contained some particular value. It would not provide a
new
value automatically.
The correct SQL for that is
ALTER TABLE x ALTER COLUMN keyfield Integer NOT NULL PRIMARY KEY DEFAULT
NewID()

or
ALTER TABLE x ALTER COLUMN keyfield Int AUTOINC [NEXTVALUE
NextValue[STEP
StepValue]]

You triugger would not fail if you used this command
INSERT INTO x (Crrefno) VALUES ( 1)
but will fail for
INSERT INTO x (Crrefno) VALUES (2)
-Anders

"Barley Man" <BarleyMan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7845AF4C-937F-4E69-A1C6-C23AAA62A319@xxxxxxxxxxxxxxxx
Guys......

I fully understand that it's me that's stupid but I can't get ANY of
your
suggestions to work! If I use the tastrade example (so I can see how
it
works), I simply CANNOT add a new record when browing ANY of the
tables as
there is vastly too much other rubbish preventing me from adding a new
record
no matter how I do it and thus I can't get to see HOW it works. If you
doubt
me, just try browsing any of the tables affected and try pressing ctrl
y,
you
will see exactly what I mean. I haven't manged to insert a single
record
into
ANY of the tables while browing!

Secondly, I cannot see how I make any of the suggestions work as even
the
most basic attmept fails for me. I have tried the most simple of
routines
just to get a handle on this. For example, with an empty table with a
numeric
(4,0) field of Crrefno, I have tried entering crrefno=1 in the 'insert
trigger' field and, if I then use ctrl y on the table, I get 'Trigger
failed'. That implies that I am making the error in the very simplest
of
stuff, i.e, the inserting of the value once I have created it!

Please tell me what the correct syntax is that I should place in the
'insert
trigger' assuming that's where the 'initiation' of the function should
be
inserted.

Ian

"Craig Berntson" wrote:

This may help. http://www.craigberntson.com/Articles/kb006.htm

--
----
Craig Berntson
MCSD, Visual FoxPro MVP
Salt Lake City Fox User Group
"Barley Man" <BarleyMan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A7F1F86A-4900-4FCA-A4BF-2757B7FBF1F7@xxxxxxxxxxxxxxxx
No Auto Incremental field value appears built into VFP7. It has
been
suggested to me that I could build such a tool using an UDF in the
'default'
property of a table.

I assume I need the 'create table' statement and then wil need a
separete
UDF

Can anyone suggest the coding and tell me EXACTLY where to put it
with
what
syntax assuming the following is the 'create' command. I need to
Autoincrement the field iIrefno by one on each new record.

CREATE TABLE inv ;
( ;
iIrefno n(10,0) , ;
iCrefno i(10) , ;
nAmount n(10,2) , ;
)

I have been doing the incrementation by a much more clumsy method
up
until
now, so , if it can be done more elegantly.......

Ian










.



Relevant Pages

  • Re: Autoincremental field in VFP7
    ... table held within the Keys table (or else it create new entries in the ... I made a gross mistake and pointed you to CREATE TRIGGER ON INSERT ... ALTER TABLE x ALTER COLUMN keyfield Integer NOT NULL PRIMARY KEY DEFAULT ... You triugger would not fail if you used this command ...
    (microsoft.public.fox.helpwanted)
  • Re: Autoincremental field in VFP7
    ... table held within the Keys table (or else it create new entries in the ... "Anders Altberg" wrote: ... ALTER TABLE x ALTER COLUMN keyfield Integer NOT NULL PRIMARY KEY DEFAULT ... MCSD, Visual FoxPro MVP ...
    (microsoft.public.fox.helpwanted)
  • Re: Autoincremental field in VFP7
    ... ALTER TABLE x ALTER COLUMN keyfield Integer NOT NULL PRIMARY KEY ... MCSD, Visual FoxPro MVP ... This type of problem is exactly why I have stayed away from integer keys ... GUIDs for primary keys. ...
    (microsoft.public.fox.helpwanted)
  • Re: Autoincremental field in VFP7
    ... I made a gross mistake and pointed you to CREATE TRIGGER ON INSERT .command. ... ALTER TABLE x ALTER COLUMN keyfield Int AUTOINC [NEXTVALUE NextValue[STEP ... You triugger would not fail if you used this command ...
    (microsoft.public.fox.helpwanted)