dbTalk Databases Forums  

Unique PKs in VFP 6

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss Unique PKs in VFP 6 in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default Unique PKs in VFP 6 - 07-05-2004 , 10:58 PM






I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Reply With Quote
  #2  
Old   
Fred Taylor
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-05-2004 , 11:21 PM






Make an index on the PK and make it a Primary type index. Those must be
unique.

Fred
Microsoft Visual FoxPro MVP


"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #3  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-06-2004 , 12:51 AM



[reordered to chronological]

"Fred Taylor" <ftaylor (AT) mvps (DOT) org!REMOVE> wrote:

Quote:
"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote in message
news:3m8ke0dd2b7brnb8s5ievmlfi0poq6n13l (AT) 4ax (DOT) com...
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Make an index on the PK and make it a Primary type index. Those must be
unique.
Thank you. I only looked at the index part of the field tab and
missed that other tab.

Now what about integrity on FKs (foreign keys)?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #4  
Old   
Anders Altberg
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-06-2004 , 04:26 AM



A stored procedure that opens the parent table if needed and then does a
Seek().
-Anders

"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
[reordered to chronological]

"Fred Taylor" <ftaylor (AT) mvps (DOT) org!REMOVE> wrote:

"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote in message
news:3m8ke0dd2b7brnb8s5ievmlfi0poq6n13l (AT) 4ax (DOT) com...
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Make an index on the PK and make it a Primary type index. Those must be
unique.

Thank you. I only looked at the index part of the field tab and
missed that other tab.

Now what about integrity on FKs (foreign keys)?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #5  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-06-2004 , 11:29 AM



[reordered to chronological: Top posting is very difficult to follow
in the technical discussion.]

"Anders Altberg" <x_pragma (AT) telia (DOT) com> wrote:

Quote:
"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote in message
news:1cfke0lnt1o4nmkl7p3c20pokpr1ft6i89 (AT) 4ax (DOT) com...
[snip]

Quote:
Now what about integrity on FKs (foreign keys)?

A stored procedure that opens the parent table if needed and then does a
Seek().
I am trying to avoid stored procedures, particularly for
something that should not need it.

What about the foreign key constraint? I have put this in, but
it appears to get ignored when I try adding records. (gendbc does
recognise it in an existing database table and generates the code for
it though.)

I might well be doing it wrong. One problem point: I really do
not see why there has to be an index on the FK column, but even having
created that index, FK integrity checking does not work.

This is my gendbc-generated code:

********** Start of Included Code ***********
************************************************** *******
* *
* * 07/06/04 TRY.DBC 09:12:31
* *
* ************************************************** *******
* *
* * Description:
* * This program was automatically generated by GENDBC
* * Version 2.26.67
* *
* ************************************************** *******


CLOSE DATA ALL
CREATE DATABASE 'TRY.DBC'
MakeTable_TWO()
MakeTable_ONE()
MakeRelation_1()

FUNCTION MakeTable_TWO
***** Table setup for TWO *****
CREATE TABLE 'TWO.DBF' NAME 'TWO' (THEKEY2 C(3) NOT NULL, ;
THEDATA2 C(10) NOT NULL)

***** Create each index for TWO *****
SET COLLATE TO 'MACHINE'
ALTER TABLE 'TWO' ADD PRIMARY KEY THEKEY2 TAG THEKEY2

***** Change properties for TWO *****
ENDFUNC

FUNCTION MakeTable_ONE
***** Table setup for ONE *****
CREATE TABLE 'ONE.DBF' NAME 'ONE' (THEKEY C(10) NOT NULL CHECK
RIGHT(TRIM(thekey),1)="9" ERROR 'Key should end with "9".', ;
THEDATA C(20) NOT NULL CHECK LEN(TRIM(thedata))=>10
ERROR "Data should be at least ten characters long.", ;
THELOOKUP C(3) NOT NULL)

***** Create each index for ONE *****
SET COLLATE TO 'MACHINE'
INDEX ON THELOOKUP TAG FK
ALTER TABLE 'ONE' ADD PRIMARY KEY THEKEY TAG THEKEY

***** Change properties for ONE *****
ALTER TABLE 'ONE' SET CHECK
LEFT(LTRIM(thekey),1)=LEFT(LTRIM(thedata),1) ERROR "Data should start
with the same non-blank character that the key starts with."
ENDFUNC

*************** Begin Relations Setup **************

FUNCTION MakeRelation_1
ALTER TABLE 'ONE' ADD FOREIGN KEY TAG FK REFERENCES TWO TAG THEKEY2
ENDFUNC


FUNCTION DisplayStatus(lcMessage)
WAIT WINDOW NOWAIT lcMessage
ENDFUNC
********** End of Included Code **********

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #6  
Old   
swdev2
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-07-2004 , 01:09 AM



Gene ? and Primary Keys ?
in most of my existentence in this realm - the two don't fit into a Venn
diagram .

but - in the meantime [big boy] -
look for newid() function in the classlibs for 6/7/8/9
and go forth .
--
PS - welcome to the database container .
--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply via
email.
Mondo Cool TeleCom -> http://www.efgroup.net/efgcog.html
Mondo Cool WebHosting -> http://www.efgroup.net/efglunar.html
Mondo Cool Satellites -> http://www.efgroup.net/sat
VFP Webhosting? You BET! -> http://efgroup.net/vfpwebhosting
mySql / VFP / MS-SQL

"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #7  
Old   
swdev2
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-07-2004 , 01:14 AM



Hullo Big Gene ...
another THING .
for Primary Keys / Foreign Keys to WORK ?
you have to enforce referential integrity in the database container .
and *that* is always, I mean always [did I mention always? ] handled
via RI code in the DBC in triggers for insert / delete / update .
study the helpfile in the pirated IDE your boss has.
You'll be fine .
regards [Bill]
--
William Sanders / Electronic Filing Group Remove the DOT BOB to reply via
email.
Mondo Cool TeleCom -> http://www.efgroup.net/efgcog.html
Mondo Cool WebHosting -> http://www.efgroup.net/efglunar.html
Mondo Cool Satellites -> http://www.efgroup.net/sat
VFP Webhosting? You BET! -> http://efgroup.net/vfpwebhosting
mySql / VFP / MS-SQL

"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #8  
Old   
Craig Berntson
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-07-2004 , 10:55 AM



Will this help?
http://www.craigberntson.com/Articles/kb006.htm

--
Craig Berntson
MCSD, Visual FoxPro MVP
Author, CrysDev: A Developer's Guide to Integrating Crystal Reports
www.craigberntson.com
email iamcraig (AT) craigberntson (DOT) com (remove iam)
Salt Lake City Fox User Group
www.slcfox.org


"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I am starting to dig into databases (contra free tables). How do
I enforce the PK being unique? What expression do I use for my
validation rule?

While I am at it, how do I enforce FK being valid?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #9  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-07-2004 , 12:03 PM



"swdev2" <wsanders.bob (AT) bob (DOT) efgroup.com> wrote:

Quote:
Gene ? and Primary Keys ?
in most of my existentence in this realm - the two don't fit into a Venn
diagram .
It happens that I do use PKs and have for over twenty years. It
is simply that they have been app-enforced. This was the correct
decision at the time it was made but is now being revised.

As a review of Venn diagrams, below is an example of two mutally
exclusive sets:

+-----------------------+
Quote:
U |
+-----+ +-----+ |
| A | | B | |
| | | | |
+-----+ +-----+ |
|
+-----------------------+

As you can now see, they do fit into a Venn diagram.

Quote:
but - in the meantime [big boy] -
look for newid() function in the classlibs for 6/7/8/9
and go forth .
--
PS - welcome to the database container .
Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #10  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: Unique PKs in VFP 6 - 07-07-2004 , 12:03 PM



"Craig Berntson" <iamcraig (AT) craigberntson (DOT) com> wrote:

Quote:
Will this help?
http://www.craigberntson.com/Articles/kb006.htm
No, as I got PKs fine. Now, the trouble is FKs.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.