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

Foreign key, ALTER TABLE syntax

Status
Not open for further replies.

Burtraskkutaren

Programmer
Oct 3, 2005
2
SE
Hi all

Trying to find an answer to a few problems but still nothing really helpful. The basics:
A simple database for testing purposes with relationships between them. Creating the foreign key when creating tables, not allowed since the referenced table isn't created yet. ALTER TABLE, works fine but when I try to use ON UPDATE CASCADE/DELETE/SET NULL it won't work. Error message:SQL Syntax in constraint is wrong. Yet, the syntax is correct according to MS own pages on the net.

OK, but not what I want:
ALTER TABLE Strings_T ADD CONSTRAINT FK_Floats_ID FOREIGN KEY (Floats_ID) REFERENCES Floats_T ;

Gives me a SQL Syntax error:
ALTER TABLE Strings_T ADD CONSTRAINT FK_Floats_ID FOREIGN KEY (Floats_ID) REFERENCES Floats_T (id) ON UPDATE CASCADE ON DELETE CASCADE ;

Might have missed something in the code right now, typing on my laptop and not having the SQL code right now but it should be correct. Can anybody help me out with what's wrong?

One solution would be to remove the FK when I update/delete but shouldn't be necessary and how do I do that with SQL syntax in Access?

Best regards from a chilly Sweden
 
Hi
Does it have to be SQL? I do not think you can do the cascade delete / update bit with sql, but you can with TableDefs.
 
Hi

Never worked with TableDefs (as I can remember right now) so I can't say if it would be possible using it in this solution. Yet, it seems to me like it is out of the question since the goal is to do the job from an application with great flexibility concerning the database program. Access, MySQL, Postgre and possibly others. If you with TableDefs mean some way in Access without access through ODBC, it's no primary option for me. But thanks for the input and I hope my feeling is wrong :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top