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

CREATE TABLE/foreign key problem 1

Status
Not open for further replies.

jwigal

Programmer
Mar 16, 2001
31
US
I am trying to create via a CREATE TABLE command (CurrentDB.Execute sql) a single table that links a "referee" from one table with a "team" from a team table.

I know how to do this manually via the Table design view, but I need to do this programmatically via VB code.

Table "Referee Data"
Primary Key Field Name: "ID"

Table "Teams"
Primary Key Field Name: "ID"

Here is the basic command that works correctly:
Code:
CREATE TABLE TeamConflict2 ( 
 RefereeID Long NOT NULL 
 CONSTRAINT FKReferee
 REFERENCES [Referee Data] (ID),

 TeamID Long NOT NULL
 CONSTRAINT FKTeam
 REFERENCES [Teams] (ID),

 CONSTRAINT RefTeam
 PRIMARY KEY (RefereeID, TeamID)
);
I am trying to set this up so that if the referee's record, from the table "Referee Data" is deleted, the corresponding records in TeamConflict2 are also deleted.

Also, if the team's record, from the table "Teams" is deleted, the corresponding records in TeamConflict2 are also deleted.

I have tried each of the following:

Code:
CREATE TABLE TeamConflict2 ( 
 RefereeID Long NOT NULL 
 CONSTRAINT FKReferee
 REFERENCES [Referee Data] (ID)
 ON DELETE CASCADE,

 TeamID Long NOT NULL
 CONSTRAINT FKTeam
 REFERENCES [Teams] (ID)
 ON DELETE CASCADE,

 CONSTRAINT RefTeam
 PRIMARY KEY (RefereeID, TeamID)
);

and


Code:
CREATE TABLE TeamConflict2 ( 
 RefereeID Long NOT NULL 
 CONSTRAINT FKReferee
 REFERENCES [Referee Data] (ID),

 TeamID Long NOT NULL
 CONSTRAINT FKTeam
 REFERENCES [Teams] (ID),

 CONSTRAINT RefTeam
 PRIMARY KEY (RefereeID, TeamID)
 ON DELETE CASCADE
);

Each time I get a "syntax error in CONSTRAINT clause".

Any thoughts? What am I missing here?

----------
Jeff Wigal
Referee Assistant for MS Access
 
I didn't take a look at the links, but I tried the same with an ADO syntax, e.g.:

Code:
CurrentProject.Connection.Execute sql

with my "example #1" defined as the string sql, and it worked right away.

Thanks!

----------
Jeff Wigal
Referee Assistant for MS Access
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top