Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a Primary Key

Status
Not open for further replies.

mans

Programmer
Joined
Mar 18, 2000
Messages
136
Location
AU
Hello,

I am familiar with creating new fields and tables in Access2000 using VB6, and setting certain features of that field such as data type etc.

I would appreciate it if I can see some code that demonstrates how I can make a pre-existing field a primary key (there will be no replication errors), there are 4 other field that are part of the current primary key in the table.


Thank You
 
Hi,

Use the .execute method of the connection object to execute an ALTER table statement. It should look something like:

ALTER TABLE tblMyTable ADD CONSTRAINT PK_MyPrimaryKey (MyColumnName)
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thank you for your response.

When I put in this statement an error message says that I have a pre-existing primary key. I have 4 fields in the current primary key and I wish to add a fifth field. If the field is called field1 and the table is called Table1, do you know how I can re-write the statement so it does not come up with the error message.

Thanks Again
 
Hi agian,

Drop the old primary key before you make a new one, something like:

ALTER TABLE tblMyTable DROP CONSTRAINT PK_MyPriamryKey



Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top