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 8614921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:14:32+00:00 2026-06-12T05:14:32+00:00

I have two tables, round and event. One round has many events. create table

  • 0

I have two tables, round and event. One round has many events.

create table round (
    round_id INTEGER AUTO_INCREMENT NOT NULL,
    round_start_date DATETIME NOT NULL,
    round_end_date DATETIME NOT NULL,
    CONSTRAINT round_pk PRIMARY KEY (round_id)
);

create table event (
    event_id INTEGER AUTO_INCREMENT NOT NULL,
    round_id INTEGER NOT NULL,
    event_date DATETIME NOT NULL,
    CONSTRAINT event_pk PRIMARY KEY (event_id),
    CONSTRAINT round_fk FOREIGN KEY (round_id) REFERENCES round (round_id),
);

When a row is inserted into the event table, I want to use a trigger to compare the event_date field of the newly inserted row to the round_start_date and round_end_date fields in its corresponding entry in the round table. If event_date is earlier than round_start_date, round_start_date should be updated with the new event_date. If event_date is after round_end_date, round_end_date should be updated with the new event_date.

This is my trigger. It does not work, and I do not understand why. I cannot find anywhere on the web where anyone else has tried to use a datetime type in a trigger, so I have no frame of reference for where I am going wrong.

create trigger update_round_date
after insert on event for each row
begin
    declare curSdate datetime;
    declare curEdate datetime;
    set curSdate = (select round_start_date from round where round_id = NEW.round_id);
    set curEdate = (select round_end_date from round where round_id = NEW.round_id);
    if (NEW.event_date < curSdate) then
        update round set round_start_date = NEW.event_date where round_id = NEW.round_id;
    else if (NEW.event_date > curEdate) then
        update round set round_end_date = NEW.event_date where round_id = NEW.round_id;
    end if;
end;

EDIT: I simply can’t create the trigger. phpMyAdmin gives me this error:
“#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 4″

EDIT 2: Updated with a delimiter set

DELIMITER $$
create trigger update_round_date
after insert on event for each row
begin
    declare curSdate datetime;
    declare curEdate datetime;
    set curSdate = (select round_start_date from round where round_id = NEW.round_id);
    set curEdate = (select round_end_date from round where round_id = NEW.round_id);
    if (NEW.event_date < curSdate) then
        update round set round_start_date = NEW.event_date where round_id = NEW.round_id;
    else if (NEW.event_date > curEdate) then
        update round set round_end_date = NEW.event_date where round_id = NEW.round_id;
    end if;
end$$

This returns the error: “#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 13″

  • 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-12T05:14:34+00:00Added an answer on June 12, 2026 at 5:14 am

    MySQL is probably stopping at the first ‘;’, interpreting your command as:

    create trigger update_round_date 
    after insert on event for each row
    begin
        declare curSdate datetime;
    

    You have to set your delimiter to something else first, then terminate the create trigger command with that delimiter instead (and put the delimiter back at the end):

    delimiter ^
    
    create trigger update_round_date 
    after insert on event for each row
    begin
        ...
    end;
    
    ^
    
    delimiter ;
    

    I believe the last semicolon after end may be necessary.

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

Sidebar

Related Questions

I have two tables, one called Events and one called Documents. Each table has
I have two tables connected with one to many relationship. Parent Table is a
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables that are joined together. A has many B Normally you
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables in my MySQL database, one is a library of all

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.