2

I am a beginner in Delphi and I have a Firebird database with 2 tables namely masterlist and daily collection. I used Zeos 7.0.3 to access my Firebird database.

My masterlist contains the following columns:

╔══════╦══════╦═════════╦════════╗
║ name ║ date ║ balance ║ status ║
╚══════╩══════╩═════════╩════════╝

My daily collection contains the following columns:

╔══════╦══════╦═════════╦═════════╗
║ date ║ name ║ payment ║ balance ║
╚══════╩══════╩═════════╩═════════╝

I would like to build a relation in which the balance from masterlist will be copied to the balance column of the daily collection, and when I update the column in the daily collection it will also update the content of the masterlist.

Hope this will be considered a good question I have tried very hard to make a useful question.

Paul White
95.4k30 gold badges440 silver badges689 bronze badges
asked Apr 20, 2013 at 23:01

1 Answer 1

2

While I'm pretty sure you should redesign your database at first (and probably read something on SQL basics), you can get what you want with triggers :)

This one inserts row into daily collection with appropriate balance:

CREATE trigger masterlist_ai for masterlist
active after insert position 0
AS
begin
 insert into "daily collection" ( "date", balance)
 values (new."date", new.balance);
end

And this one updates balance in masterlist after updates of daily collection (assuming date is the primary key):

CREATE trigger "daily_collection_au" for "daily collection"
active after update position 0
AS
begin
 update masterlist
 set balance = new.balance
 where "date" = new."date";
end
answered Jun 10, 2013 at 14:27
1
  • Also you can find better names for "date" (it's a keyword and you'll have to use quotes everywhere). Commented Jun 10, 2013 at 14:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.