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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I create a primary key in a dbf

Status
Not open for further replies.

borsker

Programmer
Joined
Jul 24, 2002
Messages
147
Location
US
Trying to create a primary key in a table. Right now we can do it through wizards but we want to do it programmatically.
 
Use the Alter Table command, something like:

ALTER TABLE Vendor ALTER COLUMN VendorId I PRIMARY KEY

Regards,
Jim
 
I am getting an error called
feature is not supported for non-.dbc tables
 

To create a primary key the table has to be in a Database, not a free table.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
how can I change or create a database from a free table programmatically.
 
Code:
CREATE DATABASE MyDatabase
ADD TABLE MyTable

That said, while free tables don't support primary keys, they do support candidate keys and that may be sufficient for your needs:

Code:
ALTER TABLE MyTable ALTER COLUMN MyKey UNIQUE

Tamar
 
Hi Tamar,

perhaps a little mistake, but it's
Code:
SELECT table
INDEX ON eExpression TAG cTagname CANDIDATE ADDITIVE
to create a candidate index. A Unique index will allow double values but only index the first occurance. Nice for deleting duplicates, but not a replacement for a primary key.

Bye, Olaf.
 
Hi Tamar,

sorry, I should have read ALTER TABLE in the help first. Yes, indeed UNIQUE within the ALTER TABLE command will generate a candidate index. A bit irritating, isn't it?

Bye, Olaf.
 
Yes, it is annoying, but I assume that UNIQUE is the standard SQL keyword for that functionality.

Tamar
 
Well I ended up downloading a fox pro driver from microsoft that will enable me to get around making a primary key. The whole point was to use a .dbf in a software called XMPIE. however if the dbf does not have a primary key it will not work. the driver i got will enable the dbf to work without selecting a primary key. thanks for everyones help. the driver is called vfpoledb.exe from the microsoft website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top