Board index » delphi » MSSQL, D3C/S: Primary --> Foreign Keys

MSSQL, D3C/S: Primary --> Foreign Keys

Hi !

I'm migrating an D3 C/S Application to a MS SQL Server 6.5 database.
I have 2 tables (similar to Master/Detail tables).

Quotations
----------------
Row_ID autoincrement and PRIMARY KEY
.... (some customer data)

Positions
--------------
Row_ID autoincrement and PRIMARY KEY
Quotation_ID FOREIGN KEY --> Quotations:Row_ID

When a user creates a new quotation i do a TQuotation.Append. The user fills
out the data and pushed a button <ADD POSITION> witch opens a new form and
performs a TPosition.Append.

After the user exits the detail form a Position.POST is performed

Error:
Project Offres.exe raised exception class EDBEngineError with message 'Key
violation'
[Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement conflicted
with COLUMN FOREIGN KEY constraint
'FK_Position_1__14'. The conflict occurred in database
'Offres',table'Quotations',column'Row_ID'

I tried to do the following Position['Quotation_ID']:=Quotation['Row_ID'] ..

Am i completely wrong ??? Isn't there any Row_ID before a Quotation.Post ?
Do i have to make a post before adding a position ???????

Please help, i'm under time pressure  .....

Thanks and greetings from Luxembourg

Serge

P.S.: Please forward your post by email because i can't access newsgroups
every day

 

Re:MSSQL, D3C/S: Primary --> Foreign Keys


We use D3 C/S and SQL Server 6.5 too. We use a lot master/detail tables
with primary key as Identity fields (autoincrement).

YES, You have to post the table to get a value for the autoincrement
field. You need to post your quotation table before accessing its
identity field.

Thanks
Chitra

Quote
Serge Wagener wrote:

> Hi !

> I'm migrating an D3 C/S Application to a MS SQL Server 6.5 database.
> I have 2 tables (similar to Master/Detail tables).

> Quotations
> ----------------
> Row_ID autoincrement and PRIMARY KEY
> .... (some customer data)

> Positions
> --------------
> Row_ID autoincrement and PRIMARY KEY
> Quotation_ID FOREIGN KEY --> Quotations:Row_ID

> When a user creates a new quotation i do a TQuotation.Append. The user fills
> out the data and pushed a button <ADD POSITION> witch opens a new form and
> performs a TPosition.Append.

> After the user exits the detail form a Position.POST is performed

> Error:
> Project Offres.exe raised exception class EDBEngineError with message 'Key
> violation'
> [Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement conflicted
> with COLUMN FOREIGN KEY constraint
> 'FK_Position_1__14'. The conflict occurred in database
> 'Offres',table'Quotations',column'Row_ID'

> I tried to do the following Position['Quotation_ID']:=Quotation['Row_ID'] ..

> Am i completely wrong ??? Isn't there any Row_ID before a Quotation.Post ?
> Do i have to make a post before adding a position ???????

> Please help, i'm under time pressure  .....

> Thanks and greetings from Luxembourg

> Serge

> P.S.: Please forward your post by email because i can't access newsgroups
> every day

Re:MSSQL, D3C/S: Primary --> Foreign Keys


Thanks for your quick answer. At least i know which way to go now ...

Do i have to do a SELECT after the post to get the field filled ?

like:
TQuotation.Post
TQuotation.ExecSQL (which is a SELECT statement)

After the TPosition.Append i have to assign the foreign key MANUALLY to the
PRIMARY key as far as i know, so i have to do
TPosition['Quotation_ID']:=TQuotation['Row_ID'] ? (That's why i asked if i
had to do a SELECT after the POST to get the ID in Row_ID)

Serge

Other Threads