Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create a primary key compound by two or more fie
Message
 
 
To
21/05/2001 15:15:17
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00509511
Message ID:
00509636
Views:
19
This message has been marked as the solution to the initial question of the thread.
>I was trying this one:
>ALTER TABLE MyTable ADD PRIMARY KEY Field1 + Field2 + Field3 tag pk
>but I get....Operator/operand type mismatch. Field2 is char, but that's not would be trouble, well, I think.
>
>Sorry by my ignorance, if I have this records...
>Field1 Field2 Field3
>----------------------------
>4 5 1
>3 1 6
>
>it will be a duplicate key? (i.e. 4+5+1=10 and 3+1+6=10 too!!!)
>
>
>Thanks a lot!!!

All fields being concatenated must be of the same type or be able to be converted to the same type. Also, you can not, or better put should not, concatenate integer/numeric expressions, for the reason you gave.

In order to concatenate your keys, you should convert them to character. You should also pad them with some expression so that values with different lengths (e.g. 5 and 10) do not step on each other when converted. Ex.
ALTER TABLE MyTable ADD PRIMARY KEY padl(Field1,5,'0') + Field2 + padl(Field3,5,'0') tag pk
The above works if Field1 and Field3 are integers and Field2 is a character. If all are numeric/integer, use PADL on all of them.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform