#1  
Old 5th March 2012, 10:53 AM
pierrotsc pierrotsc is offline
Member
 
Join Date: Nov 2011
Posts: 54
Default Referential integrity-Don't know what i am doing

If there are any example on how to setup a simple master/details database that when you insert a new record in the master, it will create one automatically in the details, please let me know.

Right now I am getting this error:
NexusDB: nxTable_trials: Referential Integrity Violation. Trials(Project_No) -> Projects(Project_No): Master record missing. [$2605/9733].

My master database is called projects:
Project_No (autoinc)
Description

Details database is called trials:
Trial_No
Project_No
Description

In the referential integrity of trials, I tell that Project_No from trial to be associated with Project_No from project.

I do the same thing under the component nxTable_trials. I tell it what the mastersource is and assign the index to match.

Under the newrecord property of the master table, I have this command:
nxTable_trials. insert; // to create a new detail record when a master one is created.

Under the new record property of the detail table, I have:
EmbeddedDM.nxTable_trials.FieldValues['Project_No'] :=
EmbeddedDM.nxTable_Projects.FieldByName('Project_N o')
.AsInteger;

Do I have to write that? Or is that supposed to be assign automatically?

Well, anyway, this setup triggers the error I wrote above.
If some kind soul can tell me on how to fix that, that would lower my frustration level.

Thanks.
P
  #2  
Old 5th March 2012, 03:23 PM
Zoran
 
Posts: n/a
Default Re: Referential integrity-Don't know what i am doing

On Mon, 5 Mar 2012 09:53:13 +1100, pierrotsc
<pierrotsc.58xct6@nx-forums.nexusdb.com> wrote:

>
>In the referential integrity of trials, I tell that Project_No from
>trial to be associated with Project_No from project.
>


That's ok. Also in Actions check off Target Required.


>I do the same thing under the component nxTable_trials. I tell it what
>the mastersource is and assign the index to match.


This is just for your DB grids to display correct child rows.


>Under the newrecord property of the master table, I have this command:
>nxTable_trials. insert; // to create a new detail record when a master
>one is created.

....
>Do I have to write that? Or is that supposed to be assign
>automatically?



After you insert new master record, get Primary Key for it
('('Project_No') using LASTAUTOINC.

When you insert new row in detail table, populate it's 'Project_No'
with this value. Nothing is automatically assigned.

  #3  
Old 5th March 2012, 09:58 PM
Keith Johnson[NDX]
 
Posts: n/a
Default Re: Referential integrity-Don't know what i am doing

Not sure if you know about this, if you right click the database in
Enterprise Manager and select referential integrity a simple GUI editor
comes up, in your example all you would then need to do is drag the
ProjectNo from the Details to the Master ProjectNo to create the link.


On 04/03/2012 22:53, pierrotsc wrote:
> If there are any example on how to setup a simple master/details
> database


  #4  
Old 6th March 2012, 03:12 AM
pierrotsc pierrotsc is offline
Member
 
Join Date: Nov 2011
Posts: 54
Default

Quote:
Originally Posted by Zoran View Post
After you insert new master record, get Primary Key for it
('('Project_No') using LASTAUTOINC.
thank for all your explanation. Could you elaborate on the part above?
Is that something i set in my datbase structure?
Right now the field of Project_no is set to autoinc.
When i insert a new record, I just click on a + in the navigation toolbar of my grid.

Thanks.
P
  #5  
Old 6th March 2012, 03:46 AM
Keith Johnson[NDX]
 
Posts: n/a
Default Re: Referential integrity-Don't know what i am doing

On 05/03/2012 15:12, pierrotsc wrote:
> Zoran;91543 Wrote:
>>
>> After you insert new master record, get Primary Key for it
>> ('('Project_No') using LASTAUTOINC.


Zoran is making reference to when your inserting records using SQL, if
your using nxTables, and your using MasterSource etc, then you don't
need to do anything when inserting new records, Delphi MasterSource will
handle that for you.
  #6  
Old 6th March 2012, 08:58 AM
Zoran
 
Posts: n/a
Default Re: Referential integrity-Don't know what i am doing


Assuming (in the meantime) you didn't change position in the master
table...

I seldom use nxTable. That's why I was thinking 'sql'...

Thanks for clarification.



On Mon, 05 Mar 2012 15:46:26 +0000, "Keith Johnson[NDX]"
<kpj_comp@yahoo.co.uk> wrote:

>Zoran is making reference to when your inserting records using SQL, if
>your using nxTables, and your using MasterSource etc, then you don't
>need to do anything when inserting new records, Delphi MasterSource will
>handle that for you.

  #7  
Old 6th March 2012, 10:44 PM
Keith Johnson[NDX]
 
Posts: n/a
Default Re: Referential integrity-Don't know what i am doing

On 05/03/2012 20:58, Zoran wrote:
>
> Assuming (in the meantime) you didn't change position in the master
> table...


Correct, but of course that would be the desired effect

For DB Editing my personal favourite is memory table backed TnxTables,
you get the benefits of TDataset event notification without the
pitfalls. TDataset event notification isn't as bad as some people make
out if you understand it's principles.

But for reports etc, SQL is my weapon of choice.


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Referential Integrity question Scott Slater nexusdb.public.support 3 15th February 2012 07:41 AM
Referential Integrity pierrotsc nexusdb.public.support 2 25th January 2012 12:18 PM
Referential Integrity Mark Mitton nexusdb.public.support 1 3rd March 2006 01:09 PM
Re: V2 and referential integrity Robert Meek nexusdb.public.support 1 13th March 2005 09:14 AM
Referential integrity! Atmapuri nexusdb.public.support 6 30th September 2003 08:45 AM


All times are GMT +11. The time now is 09:03 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.