Re: Autoincremental field in VFP7
- From: "Anders Altberg" <anders altberg>
- Date: Mon, 12 Feb 2007 22:09:54 +0100
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.numeric
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
feild, as I was!Keys
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
table ITSELF!) and that getkey() MUST be issued as getkey(tablename) where..command.
'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
checkAltogether wrong. That would create a table validation rule that would
newif the insert contained some particular value. It would not provide a
NextValue[STEPvalue 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
yourStepValue]]
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
itsuggestions to work! If I use the tastrade example (so I can see how
tables asworks), I simply CANNOT add a new record when browing ANY of the
y,there is vastly too much other rubbish preventing me from adding a newrecord
no matter how I do it and thus I can't get to see HOW it works. If youdoubt
me, just try browsing any of the tables affected and try pressing ctrl
recordyou
will see exactly what I mean. I haven't manged to insert a single
theinto
ANY of the tables while browing!
Secondly, I cannot see how I make any of the suggestions work as even
routinesmost basic attmept fails for me. I have tried the most simple of
ofjust to get a handle on this. For example, with an empty table with anumeric
(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
bestuff, i.e, the inserting of the value once I have created it!'insert
Please tell me what the correct syntax is that I should place in the
trigger' assuming that's where the 'initiation' of the function should
beeninserted.
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
withseparetesuggested 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
UDF
Can anyone suggest the coding and tell me EXACTLY where to put it
upwhat
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
until
now, so , if it can be done more elegantly.......
Ian
.
- Follow-Ups:
- Re: Autoincremental field in VFP7
- From: Barley Man
- Re: Autoincremental field in VFP7
- From: Cy Welch
- Re: Autoincremental field in VFP7
- References:
- Re: Autoincremental field in VFP7
- From: Craig Berntson
- Re: Autoincremental field in VFP7
- From: Barley Man
- Re: Autoincremental field in VFP7
- From: Anders Altberg
- Re: Autoincremental field in VFP7
- From: Barley Man
- Re: Autoincremental field in VFP7
- Prev by Date: Re: determine if a file fits a file mask
- Next by Date: Re: determine if a file fits a file mask
- Previous by thread: Re: Autoincremental field in VFP7
- Next by thread: Re: Autoincremental field in VFP7
- Index(es):
Relevant Pages
|