qrk10000
01-17-2007, 02:51 PM
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?
Peter Reid
01-18-2007, 07:19 AM
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;
qrk10000
01-18-2007, 07:28 AM
Awesome! Thanks very much, Peter. I appreciate it. It worked great!
qrk10000
01-18-2007, 07:50 AM
Am I able to remove a Primary Key be switching out CREATE for DELETE or is there additional syntax needed?
qrk10000
01-18-2007, 08:08 AM
Nevermind, I was able to figure it out using the DROP INDEX statement. Thanks again for your help.
qrk10000
01-18-2007, 08:28 AM
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.