G
Guest
I have a script to create tables and relationships. It works fine when I run
it using Query Analyzer in SQL Server. However, Access seems to choke on DDL
that attempts to both create a table and set a relation in one SQL statement.
For example, I have found that running just this much as one query chokes in
Access:
CREATE TABLE Senators (
SenatorID INTEGER NOT NULL PRIMARY KEY,
SenatorName VARCHAR(100) NOT NULL,
DistrictID INTEGER NOT NULL UNIQUE,
CONSTRAINT fk__senators__districts FOREIGN KEY (DistrictID)
REFERENCES Districts (DistrictID)
ON UPDATE CASCADE ON DELETE CASCADE
)
;
When I break it up into two DDL queries, it seems to work okay, however, I
have not quite figured out how to get the last line to work, which sets
Cascade Update and Cascade Delete:
CREATE TABLE Senators (
SenatorID INTEGER NOT NULL PRIMARY KEY,
SenatorName VARCHAR(100) NOT NULL,
DistrictID INTEGER NOT NULL UNIQUE
)
;
followed by:
ALTER TABLE Senators ADD CONSTRAINT fk__senators__districts FOREIGN KEY
(DistrictID) REFERENCES Districts (DistrictID);
works in Access.
What's the correct syntax for specifying Cascade Update and Cascade Delete?
Thanks in advance
it using Query Analyzer in SQL Server. However, Access seems to choke on DDL
that attempts to both create a table and set a relation in one SQL statement.
For example, I have found that running just this much as one query chokes in
Access:
CREATE TABLE Senators (
SenatorID INTEGER NOT NULL PRIMARY KEY,
SenatorName VARCHAR(100) NOT NULL,
DistrictID INTEGER NOT NULL UNIQUE,
CONSTRAINT fk__senators__districts FOREIGN KEY (DistrictID)
REFERENCES Districts (DistrictID)
ON UPDATE CASCADE ON DELETE CASCADE
)
;
When I break it up into two DDL queries, it seems to work okay, however, I
have not quite figured out how to get the last line to work, which sets
Cascade Update and Cascade Delete:
CREATE TABLE Senators (
SenatorID INTEGER NOT NULL PRIMARY KEY,
SenatorName VARCHAR(100) NOT NULL,
DistrictID INTEGER NOT NULL UNIQUE
)
;
followed by:
ALTER TABLE Senators ADD CONSTRAINT fk__senators__districts FOREIGN KEY
(DistrictID) REFERENCES Districts (DistrictID);
works in Access.
What's the correct syntax for specifying Cascade Update and Cascade Delete?
Thanks in advance