Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Indexseek
Message
De
16/07/2004 00:46:56
 
 
À
15/07/2004 14:40:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00924849
Message ID:
00925036
Vues:
16
This message has been marked as a message which has helped to the initial question of the thread.
>How to check if one key already exists using indexseek. I know that indexseek does not consider the current record when I am inserting, but when the record is not new the indexseek check the current record too.

aaaaaaaaaaaaaaaaaaaah
primary key with possible candidate/foreign key that points back ?

that should be easy ..

think of the first column as gospel - you ain't changing /adding any more primary keys [or if you did - it would be primary/0 for the two columns]

assume for the moment that your two columns really must be unique -
then toss indexseek completely - and issue a select statement to check for the two column combination. IF
if doesn't exist ? do the insert .
DOES exist ? do something else.

one easy example I did last year was for a multi key table ...

primary key
foreign key 1
foreign key 2
foreign key 3

but - FK's 1-3 could be zero - which means a FK doesn't exist for that PK [yet] ...
if an FK was 0 but OTHERS existed - ie PK = 4, FK1 = 0, FK2 = 0, FK3 = 1
then I have an atomic / scaler 'thing' that is meaningful, and not representing the null result .

IF you want to rely on indexseek - then:
1. make a compound index -> str(pk1) + str(fk1) + str(fk2) + str(fk3),
adding the zeros as you need in a pad() statement [how big you wanna go with keys????????????
2. make you select statement, in the WHERE clause, match your compound index ..
ie ...
.............where pk1 = pad(str(pk1,8,0)) and fk1 = pad(str(fk1,8,0) ....[more that you need to write
and maybe you need to str/pad the pk1/fk... on left side of the = sign as well,

bottom line, numerical values for keys, during evaluation, CAN fail due to magnitude if you make a compound index [ie pk1+fk1+fk2+fk3.....]
but if you str/pad them ? is absolute/unique . just pick the magnitude and go forth. [magnitude here deals with length of pad - i suggest 8 - but you could use any number of pad]

gufen SQL [Bill]
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform