SQL String to Modify Multifield Keys

  • Thread starter Thread starter TT
  • Start date Start date
T

TT

I have some existing tables for which I would like to be able to
programmatically alter the primary keys. The tables have multifield primary
keys. For example, a table might have Field1 -- Field5 with Field1 and
Field2 designated as the primary keys. Can anyone give me a sample SQL
command to change the key structure so that the multifield key is Field1,
Field2 and Field3?

Thanks!
 
I'm not sure you can change the structure of an existing index: you may have
to drop it and recreate it.

Dropping would be

DROP INDEX PrimaryKey ON MyTable

(assuming your primary key is actually named PrimaryKey)

I believe recreating would be

CREATE UNIQUE INDEX PrimaryKey
ON MyTable (Field1, Field2, Field3)
WITH PRIMARY
 
Thanks -- just one question -- how can I determine what the name of the
existing primary key is? When I look at the table in design mode I can see
the several keys that comprise the multifield key, but I don't see any name
that would map onto "primarykey" in your example so that I can drop the
existing index.
 
Back
Top