How to Set Primary Key




I mostly use macros because my knowledge in vba / sql is very small.
I need to remove the primary key from one field and put it on another.

After picking around on the net I cobbled the following code together
that adds the key to the right field. However this only will add the
key if there is no key already in the table. The table im trying to
change the key on already has one. Can someone show me how to remove
the key first so that I can then run the below code to add it to the
right field. I have found several examples on the net but I cant seem
to get it to work properly.

strSql = "ALTER TABLE [tmptblStructureOnlytblLogfile] " & _
"ADD Constraint PK_tmpTblStructureonlytblLogfile PRIMARY KEY
(ComputerName)"
CurrentDb.Execute strSql, dbFailOnError

Thanks.

.



Relevant Pages

  • Re: table loses his primary key
    ... Now i want to check if the table has still his primary key. ... You can reset the PK in SQL or VBA. ... names - in SQL world they are called named constraints. ...
    (comp.databases.ms-access)
  • Re: script to load a table with many values - ACCESS 2000
    ... Kind of seeing VBA is to Jet in Access what T-SQL is to SQL in MS SQL ... You can use macros too. ... the switch /X to specify the run to start with the specified macro ...
    (microsoft.public.access.queries)
  • Select Unique Record Identifier
    ... I am using VBA to link to many SQL tables. ... Unique Record Identifier" dialog box pops up and I have to choose a field ... for the primary key. ...
    (microsoft.public.access.modulesdaovba)
  • Select Unique Record Identifier
    ... I am using VBA to link to many SQL tables. ... Unique Record Identifier" dialog box pops up and I have to choose a field ... for the primary key. ...
    (microsoft.public.access.modulesdaovba)
  • Converting
    ... I know we could convert Macros to VBA in access, but is there way that we could convert queries to VBA or MS SQL? ...
    (microsoft.public.access.queries)