1

The below statement is being used to create a table CAMPUS. I am getting the Error:

"Syntax error in CONSTRAINT clause"
"UPDATE" is highlighted signifying source of error.

By removing "ON UPDATE CASCADE ON DELETE NO ACTION" I am able to create the table with no issues.

What is the proper syntax or procedure? (the MS Access "Help" was of no help)

SQL Code:

CREATE TABLE CAMPUS(                
    CampusID    Counter(1,5)    NOT NULL,    
    UnivID    Long    NOT NULL,    
    CampusName    Text(50)    NOT NULL,    
    Address    Text(50)    NULL,    
    Zip    Number    NULL,    
    Phone    Number    NULL,               
    CONSTRAINT    CampusPK    PRIMARY KEY    (CampusID,UnivID),    
    CONSTRAINT    CampusFK    FOREIGN KEY    (UnivID)
    REFERENCES UNIVERSITY(UnivID)
    ON UPDATE CASCADE 
    ON DELETE NO ACTION
    CONSTRAINT    CampusAK1    UNIQUE    (CampusName)    
    );
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Peter
  • 11
  • 1
  • 2

2 Answers2

1

Access (ACE, Jet, whatever) has supported referential actions in its SQL DLL since Jet 4.0 (Access2000). However, they are only available in ANSI-92 Query Mode.

With effect from Access2003, the Access UI can be placed in ANSI-92 Query Mode, allowing the newer, richer SQL DDL to be executed from the SQL View of a Query. Note that ADO (OLE DB) always uses ANSI-92 Query Mode and DAO uses "traditional" ANSI-89 Query Mode (however IIRC DAO's object model has been enhanced to include all referential actions including the post-89 SET NULL action).

Therefore, I speculate that you are getting a syntax error because your are trying to execute ANSI-92 Query Mode SQL DDL while in ANSI-89 Query Mode.

Myrddin Emrys
  • 42,126
  • 11
  • 38
  • 51
onedaywhen
  • 55,269
  • 12
  • 100
  • 138
-1

It's been more then 10 years since I last used MS Access, but it seems you can only write either CASCADE or SET NULL after ON UPDATE and ON DELETE in a referential constraint.

So basically you have to omit this part

ON DELETE NO ACTION

Link http://www.sqlexamples.info/SQL/bsc_sqlddl1.htm

bpgergo
  • 15,669
  • 5
  • 44
  • 68
  • Access (ACE, Jet, whatever) has supported referential actions in its SQL DLL since Jet 4.0 (Access2000). However, despite claims made in the Access Team's documentation, Access has never supported `ON UPDATE SET NULL` (but does support `ON UPDATE DELETE`). – onedaywhen Jun 15 '11 at 07:47
  • ...and `NO ACTION` is indeed a supported referential action in SQL DDL. – onedaywhen Jun 15 '11 at 07:55