SQL syntax to change a primary key?

G

Gary Kahrau

I have a table tool and the Primary Key consists of (2) fields.
Key = id and sub_oper (unique)
I added another field to the table type_code.
Now I want the Primary Key = ID, sub_oper, type_code.

I am trying to update via VB and ADO.
All my attempts at syntax gets rejected as wrong syntax.

What is the correct syntax?

Thanks,
Gary...
-----------------------------------------------------------
Gary Kahrau - VP Technology
[email protected] (W)
[email protected] (H)
Stellex Monitor Aerospace Corp.
-----------------------------------------------------------
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

First, drop the initial PK constraint (you have to know the PK's
constraint name):

ALTER TABLE table_name DROP CONSTRAINT constraint_name

Then create the new PK constraint:

ALTER TABLE table_name ADD CONSTRAINT constraint_name PRIMARY KEY (ID,
sub_oper, type_code)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQcpX3oechKqOuFEgEQJ59gCfYMV+2qM8iZ5No/lGWKBucsrcwfsAoKYU
m+6Jbpuwf1EYSfe2dnNehqS8
=0m7H
-----END PGP SIGNATURE-----
 
Top