Using DDL to create a Foreign Key, with Delphi -


i using delphi 7 create access db ddl statements. it's going relatively simple relational database simple stock invoice system. i've managed create table called customer no problem, on trying create table called order, in order have foreign key field customerid, following error message:

"syntax error in field definition".

customerid key field in customer table , want link 2 together. here ddl statements both.

cs:= 'create table tblcustomer ('+       'customerid number,' +       'fname text(20),' +       'sname text(20),' +       'addressline1 text(35))'; adocommand1.commandtext:=cs; adocommand1.execute;  cs:='create index idxcustomerid on tblcustomer (customerid) primary'; adocommand1.commandtext:=cs; adocommand1.execute;  cs:= 'create table tblorder ('+ 'orderid number,'+ //here line!! 'customerid number constraint customerid references tblcustomer (customerid),'+ 'orderdate datetime,'+ 'create index idxprimary on tblorder (orderid) primary)'; adocommand1.commandtext:=cs; adocommand1.execute; 

i'm guessing issue foreign key declaration above. have done wrong please?

i have tried this:

cs:= 'create table tblorder ('+ 'orderid number constraint pk_orderid primary key,'+ 'customerid number constraint fk_customerid references tblcustomer (customerid),'+ 'orderdate datetime,'+ 'create index idxprimary on tblorder (orderid) primary'; 

still not working.

i found solution. constraint clause should have went follows:

cs:= 'create table tblorder ('+ 'orderid number,'+ 'customerid number constraint fk_customerid references tblcustomer (customerid),' + 'orderdate datetime)'; adocommand1.commandtext:=cs; adocommand1.execute; 

and create index clause should have been separate ddl command.

cs:='create index idxorderid on tblorder (orderid) primary'; adocommand1.commandtext:=cs; adocommand1.execute; 

thanks anyway


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -