Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:40+00:00 2026-06-09T14:53:40+00:00

I am currently new in Firebird, especially in triggers. Usually, I do this in

  • 0

I am currently new in Firebird, especially in triggers. Usually, I do this in script manually, but I am really fascinated to create it with trigger.

Please let me explain my tables first.

***STOCK***
CODE
NAME
TOTAL
GOOD
BROKEN
SERVICE
***DETAIL***
ID
STOCK_CODE
SERIAL
***BROKEN***
DETAIL_ID
MARK
***SERVICE***
DETAIL_ID
START_DATE
END_DATE
COST
***LOGS***
DETAIL_ID
MARK
START_DATE
END_DATE
COST

And now my problems:

  1. How to modify STOCK.GOOD and STOCK.BROKEN value after insert a new record into BROKEN? That will be: STOCK.GOOD-1, STOCK.BROKEN+1.

  2. How to insert all record from BROKEN and SERVICE into LOGS before current record in SERVICE is deleted?

I hope my questions could be accepted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:53:41+00:00Added an answer on June 9, 2026 at 2:53 pm

    Below are two triggers:

    CREATE TRIGGER bi_broken FOR broken
      BEFORE INSERT
      POSITION 0
    AS
    BEGIN
      UPDATE stock SET good = good - 1, broken = broken + 1
        WHERE code = (SELECT d.stock_code 
          FROM detail d WHERE d.id = NEW.detail_id);
    END
    
    
    CREATE TRIGGER bd_service FOR service
      BEFORE DELETE
      POSITION 0
    AS
    BEGIN
      INSERT INTO logs (detail_id, mark, start_date, end_date, cost)
      SELECT detail_id, (SELECT b.mark FROM broken b WHERE b.detail_id = OLD.detail_id),
        start_date, end_date, cost
      FROM service 
      WHERE detail_id = OLD.detail_id;
    END
    

    By the way, what is a reason to put mark into a separate table? It belongs to STOCK, doesn’t it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm new with ASP and WCF, but I really enjoy it and I
I am currently really new to Xcode and the whole Iphone App development but
I'm currently new into client-side programming, especially using the Jquery Ajax method to call
I'm currently developing a new web application. This is the first time I'm using
I'm currently facing new problem with operators. Using following code, I want to make
I'm currently very new with rails and quite confused. I am doing a school
I am currently configuring a new Apple Provisioning Profile and I noticed there are
I'm currently planning a new web project. Clients are going to connect using a
I'm currently building a new app based on a legacy database. In the app,
I'm currently estimating a new project. My high level estimate assuming there was one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.