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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:06:38+00:00 2026-06-16T17:06:38+00:00

Can this trigger be changed so that the sortorder table gets 2 column values

  • 0

Can this trigger be changed so that the sortorder table gets 2 column values (sortOrderId, sortOrder) inserted?

How is the value of sortOrder found?

If it is known and can be inserted into image table then can it also be inserted into the sortorder table?

-- Trigger DDL Statements
DELIMITER $$

USE `nextcart`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER `nextcart`.`insert_sortorderid` 

BEFORE INSERT ON `nextcart`.`image` 

FOR EACH ROW 
BEGIN
    INSERT INTO sortorder SET sortOrderId = NULL, sortOrder = NEW.sortOrder;

    SET NEW.sortOrderId = (SELECT LAST_INSERT_ID());
END;
$$

CREATE TABLE sortorder:

delimiter $$

CREATE TABLE `sortorder` (
  `sortOrderId` int(11) NOT NULL AUTO_INCREMENT,
  `sortOrder` tinyint(4) NOT NULL,
  PRIMARY KEY (`sortOrderId`),
  KEY `sort_order` (`sortOrderId`,`sortOrder`),
  CONSTRAINT `fk_sortOrderId` FOREIGN KEY (`sortOrderId`) REFERENCES `image` (`imageId`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8$$

CREATE TABLE image:

delimiter $$

CREATE TABLE `image` (
  `imageId` int(11) NOT NULL AUTO_INCREMENT,
  `imageFileName` varchar(45) DEFAULT NULL,
  `imagePath` varchar(255) DEFAULT NULL,
  `imageTitle` varchar(100) DEFAULT NULL,
  `imageAlt` varchar(100) DEFAULT NULL,
  `imageWidth` int(11) DEFAULT NULL,
  `imageHeight` int(11) DEFAULT NULL,
  `classId` int(11) DEFAULT NULL,
  `imageSizeId` tinyint(4) NOT NULL,
  `isImageEnabled` bit(1) DEFAULT b'0',
  `sortOrderId` int(11) DEFAULT NULL,
  PRIMARY KEY (`imageId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8$$

ERROR MESSAGE:

Error 1054: Unknown column ‘sortOrder’ in ‘NEW’ SQL Statement:
CREATE TRIGGER insert_sortorderid BEFORE INSERT ON image FOR EACH
ROW BEGIN INSERT INTO nextcart.sortorder SET sortOrderId = NULL,
sortOrder = NEW.sortOrder; SET NEW.sortOrderId = ( SELECT
LAST_INSERT_ID()); END; Error when running failback script. Details
follow. Error 1050: Table ‘image’ already exists SQL Statement: CREATE
TABLE image ( imageId int(11) NOT NULL AUTO_INCREMENT,
imageFileName varchar(45) DEFAULT NULL, imagePath varchar(255)
DEFAULT NULL, imageTitle varchar(100) DEFAULT NULL, imageAlt
varchar(100) DEFAULT NULL, imageWidth int(11) DEFAULT NULL,
imageHeight int(11) DEFAULT NULL, classId int(11) DEFAULT NULL,
imageSizeId tinyint(4) NOT NULL, isImageEnabled bit(1) DEFAULT
b’0′, sortOrderId int(11) DEFAULT NULL, PRIMARY KEY (imageId)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8

  • 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-16T17:06:39+00:00Added an answer on June 16, 2026 at 5:06 pm

    There is no column named sortOrder in the image table.

    So, the reference to NEW.sortOrder (on the insert statement in the trigger) is invalid.


    To answer your first question: No. Since there is no value supplied for that in the INSERT statement (which fires the BEFORE INSERT TRIGGER), you don’t really have a source for that value.

    The easy option is to provide a default value for it.

    If you want to supply a value for the sortOrder column, then one option is to add a sortOrder column to the image table, and then the value can be supplied in the INSERT INTO image statement. Then it would available in the trigger.

    (The purpose of the sortorder table is not at all clear.)

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

Sidebar

Related Questions

Does this mean I can't update another table from a trigger if I'm using
I have this trigger which works functionally (as far as I can tell by
The trigger below is delaying my insert response. How can I prevent this? create
I need to create trigger in SQL Server 2008 that gone insert all values
How can we trigger a mysql trigger when the system date is changed? Let's
Possible Duplicate: trigger an event when contenteditable is changed I have a table on
I created a trigger for a table (Person) so that each time a new
I need to write a trigger that will create a record in another table.
After a while of searching the internet, I found this piece of code that
I'm trying to create a trigger that will update my Orders Table with the

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.