Setting primary key

qrk10000

Registered User.
Local time
Today, 14:17
Joined
Jan 10, 2007
Messages
11
I am looking to create a primary key in a macro using RunSql but am having problems with the syntax. The name of my field is "Geo" and the name of my table is "Pre-Deletes". Here is what I came up with so far:

CREATE UNIQUE INDEX PrimaryKey ON Pre-Deletes (Geo)

Am I missing something?
 
As your table name contains a hypen, it should be enclosed with square brackets

ie

CREATE UNIQUE INDEX PrimaryKey ON [Pre-Deletes] (Geo)

However, this will only create an index called "PrimaryKey"

To create a Primary Key on the field Geo, you will have to append "with Primary" to the end of your statement

ie

CREATE Unique INDEX PrimaryKey ON [Pre-Deletes] (Geo) WITH PRIMARY;
 
Awesome! Thanks very much, Peter. I appreciate it. It worked great!
 
Am I able to remove a Primary Key be switching out CREATE for DELETE or is there additional syntax needed?
 
Nevermind, I was able to figure it out using the DROP INDEX statement. Thanks again for your help.
 
I am working on a different macro that sets a relationship between two tables: Footprint and Pre-Deletes. Here is my code:

ALTER TABLE [Footprint]
ADD CONSTRAINT FK_Geo
FOREIGN KEY (Geo)
REFERENCES [Pre-Deletes](Geo);

I get an error stating that it cannot set relationships to enfore referential integrity because data in my footprint table violates it. Is there a way to bypass this? My primary key is in the Pre-Deletes table and I merely want a relationship between the two so that I can perform deletes.

Thanks.
 

Users who are viewing this thread

Back
Top Bottom