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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:48:04+00:00 2026-05-30T07:48:04+00:00

I want to make a trigger to do this: UPDATE formulario SET ano =

  • 0

I want to make a trigger to do this:

UPDATE formulario 
    SET ano = EXTRACT(year FROM create_date),
    mes = EXTRACT(month FROM create_date) 

But i am getting a lot of trouble making it. it is accepted but doesn’t work or gives away error message on posting new rows.
I want to insert the create_date and get the ano and mes auto fitted. how can i do this ?

sorry here is the trigger defenition:

CREATE TRIGGER `anomes` AFTER INSERT ON `formulario` FOR EACH ROW BEGIN
UPDATE formulario SET ano = EXTRACT(year FROM create_date);
UPDATE formulario SET mes = EXTRACT(month FROM create_date); 
END;

and table:

-- Dumping structure for table at.formulario
CREATE TABLE IF NOT EXISTS `formulario` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `uniqid` varchar(38) DEFAULT NULL,
  `create_date` date DEFAULT NULL,
  `ano` int(4) DEFAULT NULL,
  `mes` int(2) DEFAULT NULL,
  `codcliente` int(8) DEFAULT NULL,
  `tipo_act` int(1) DEFAULT NULL,
  `contacto_nome` varchar(50) DEFAULT NULL,
  `contacto_funcao` int(1) DEFAULT NULL,
  `contacto_telefone` varchar(20) DEFAULT NULL,
  `cara_cli_abc` int(1) DEFAULT NULL,
  `cara_cli_estado` int(1) DEFAULT NULL,
  `cara_cli_tipo_est` int(3) DEFAULT NULL,
  `cara_cli_sazonal` int(1) DEFAULT '0',
  `loc_inst_piso` varchar(5) DEFAULT NULL,
  `loc_inst_acesso` int(1) DEFAULT NULL,
  `loc_inst_data_vistoria` date DEFAULT NULL,
  `loc_inst_data_inter` date DEFAULT NULL,
  `loc_inst_time_vistoria_start` time DEFAULT NULL,
  `loc_inst_time_vistoria_end` time DEFAULT NULL,
  `loc_inst_time_inter_start` time DEFAULT NULL,
  `loc_inst_time_inter_end` time DEFAULT NULL,
  `check_list_p_agua` int(1) DEFAULT '0',
  `check_list_t_agua` int(1) DEFAULT '0',
  `check_list_p_dist` varchar(3) DEFAULT NULL,
  `check_list_obs` text,
  `final_obs` text,
  `vendedor` int(4) DEFAULT NULL,
  `dt_aceito` int(1) DEFAULT NULL,
  `bonus` text,
  `anulado` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB 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-05-30T07:48:05+00:00Added an answer on May 30, 2026 at 7:48 am

    The problem is that you cannot modify the table that invoked this trigger. It is a restriction.

    Try to use a BEFORE INSERT trigger and set new values before the inserting data. For example:

    CREATE TRIGGER anomes
    BEFORE INSERT
    ON formulario
    FOR EACH ROW
    BEGIN
      SET NEW.ano = EXTRACT(year FROM NEW.create_date);
      SET NEW.mes = EXTRACT(month FROM NEW.create_date); 
    END
    

    And the question – why are you going to store this data in the table? You can calculate it on the fly in SELECT query.

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

Sidebar

Related Questions

I want to make a trigger in ms sql server which saves every insert,update
I want to make an entity that has an autogenerated primary key, but also
I want to make an animation start as soon as I trigger an event
I want to create a trigger that will update the column LastActivityDate to the
I want to trigger an update on a specifc column, when changed. (history: some
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog
I have style sheet with a class name changebackgroundcolor i want make change in
I am traversing a HTML document using javascript DOM. I want make a list
I want to make an etag that matches what Apache produces. How does apache

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.