Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 How to define Foreign Keys in script 4 MS Access?

Author  Topic 

cha0sphera
Starting Member

2 Posts

Posted - 2005-06-06 : 14:38:22


Goodday!

I'm using Query tool to write an script for automating the building process of an MS Access XP 2002 database. The challange that I'm facing at the moment is to define "Foreign Keys" in my script. But whatever I try, I keep facing the syntax errors:

<eb1>[Microsoft][ODBC Microsoft Access Driver] Syntax error in CONSTRAINT clause.
State: 37000, Native: -3550, Source: Microsoft OLE DB Provider for ODBC Drivers</eb1>

In the statements below you can see a piece of my code. I would like to define the Primary Key "Vessel_Key" from the table "Vessel" as a Foreign Key "Vessel_Key" in the table "Lightdues" to create a kind of relation between these tables.


CREATE TABLE Vessel
(
Vessel_Key varchar(10) NOT NULL,
Vessel_Name varchar NULL,
Vessel_Lloydsnumber varchar NULL,
Vessel_Hub_Remarks varchar NULL,
PRIMARY KEY (Vessel_Key)
)
GO


CREATE TABLE Lightdues
(
Lightdues_Key varchar(10) NOT NULL,
Lightdues varchar NULL,
Vessel_Key varchar(10) NOT NULL,
PRIMARY KEY (Lightdues_Key),
FOREIGN KEY (Vessel_Key) REFERENCES Vessel
ON DELETE RESTRICTED
ON UPDATE CASCADE
)
GO

What Am I doing wrong at the moment?

Best Regards,

Rio

cha0sphera
Starting Member

2 Posts

Posted - 2005-06-06 : 15:24:39
CREATE TABLE Lightdues
(
Lightdues_Key varchar(10) NOT NULL,
Lightdues varchar NULL,
Vessel_Key varchar(10) NOT NULL,
CONSTRAINT PK_Lightdues_Key PRIMARY KEY(Lightdues_Key),
CONSTRAINT Lightdues_Vessel_Key FOREIGN KEY(Vessel_Key) REFERENCES Vessel(Vessel_Key));
Go
Go to Top of Page
   

- Advertisement -