Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm working on a program that need to create databases and tables in a access database.
I need to create relationship and configure the On update to Cascade and same for on delete ( i've tryed the basic syntacs that works on SQL and MySQL but it dosn't work with access, apparently "update" causes syntacs problems ). So =>

First :
-Is it possible on access ?

Second :
-And if yes,how can i acheve it ?
Posted

You did not mention which technology you are using but I found this
Quote:
C#
OledbConnection con = new OledbConnection("Connection String");
con.Open();

//Adding Primary Key
OledbCommand comm = new OledbCommand("alter table Table1 add constraint pk_id primary key(id)",con);
comm.ExecuteNonQuery();

//Adding Foriegn Key
comm = new OledbCommand("alter table Table2 add constraint fk_id foreign key(id) references Table1(id)",con);
comm.ExecuteNonQuery();

con.Close();
from Creating relations in MS Access with C#[^].
 
Share this answer
 
Take a look at Cascade Updates in Microsoft Access[^] article.
 
Share this answer
 
Thank you very much for replying so quick, =)

But i need to create programaticaly the relation and i absolutly need the ON UPDATE and ON DELETE option to work.

The creation of the relation works but when i had "ON UPDATE" or "ON DELETE" it fails,
the error message is "syntax incorrect".

I've tryed a to configure the relation while creating the table, after creating it with "ALTER table" but still the same error message shows up =(

Can someone help me ??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900