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

  • SEARCH
  • Home
  • 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 4600962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:45:29+00:00 2026-05-21T23:45:29+00:00

I have the following two tables in a MySql database: Bookings BookingID | ClientID

  • 0

I have the following two tables in a MySql database:

Bookings
BookingID | ClientID | SeatID

SeatAvailability
SeatAvailabilityID | BookingID | ShowID | Available 

They are linked on SeatID/SeatAvailabilityID.
I’m trying to write a trigger which updates the SeatAvailability table each time a row is inserted in Bookings. The trigger should change SeatAvailability.Available to 0 and also enter the BookingID from Bookings into the BookingID field in SeatAvailability with the same SeatAvailabilityID.

I’ve written this trigger, MySql accepts it but gives an error when inserting
“ERROR 1054: Unknown column ‘cinemax.bookings.SeatID’ in ‘where clause'”.

DELIMITER $$

USE `cinemax`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER `cinemax`.`update_available`
AFTER INSERT ON `cinemax`.`bookings`
FOR EACH ROW
UPDATE cinemax.seatavailability
SET cinemax.seatavailability.Availabe=0, cinemax.seatavailability.BookingID=cinemax.bookings.BookingID
WHERE cinemax.bookings.SeatID=cinemax.seatavailability.SeatAvailabilityID$$
  • 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-05-21T23:45:30+00:00Added an answer on May 21, 2026 at 11:45 pm

    It’s a couple of months late, but I decided to give it a quick shot before handing in the overall assignment. In the meantime I switched to postgres as it seemed to offer more functionality (albeit not as user friendly). I first had to create a trigger function:

    CREATE OR REPLACE FUNCTION updateseatavailable()
    RETURNS trigger AS
    $BODY$
    BEGIN
    
                IF (TG_OP = 'INSERT') THEN
                    UPDATE "SeatAvailability"
                SET "Available"='FALSE' AND "BookingID"=NEW."BookingID" WHERE "SeatAvailabilityID"=NEW."SeatID";
    
                ELSIF (TG_OP = 'DELETE') THEN
                UPDATE "SeatAvailability"
                SET "Available"='TRUE'  WHERE "SeatAvailabilityID"=OLD."SeatID";
    
                END IF;
    
                RETURN NEW;
            END;
        $BODY$
          LANGUAGE plpgsql VOLATILE
    

    and then simply call the function/procedure from a trigger:

    CREATE TRIGGER UpdateSeatAvailable
    AFTER INSERT OR DELETE ON "Bookings"
    FOR EACH ROW
    EXECUTE PROCEDURE updateSeatAvailable();
    

    I wasn’t able to get the BookingID in SeatAvailability to update for some reason (on Insert nothing happened and on Delete I got an error telling me Available cannot be null, even though I was changing the BookingID) so I omitted that in postgres,and implemented it with Java instead. It’s not the best way but still better than nothing.

    I decided to post my solution just in case someone has a similar problem and stumbles upon this question.

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

Sidebar

Related Questions

I have the following two tables in my mysql database. Table Name: groups id
Suppose I have the following two tables in my MySQL database: Table 1:: EMP:
I have the following two mySQL tables with the 'child' table having a DELETE
I have two MySQL database tables: one containing a list of championships and another
I am designing the database (MySQL) in which I have two tables Employees and
I have two tables named t1 and t2, which content list as following: mysql>
I have an e-commerce MySQL database with the following tables: **Product** ---------- productID -
I have two tables in my SQL database: mysql> select *from crop; +------+-----------+----------+ |
Let's say I have the following scenario. A database of LocalLibrary with two tables
I am having issues with an InnoDB mysql database. E.g., I have two tables,

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.