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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:22:05+00:00 2026-06-13T17:22:05+00:00

How to create a trigger that is activated by a change in a database

  • 0

How to create a trigger that is activated by a change in a database which changes values in a table in a different database ?

One database contains the table which has the login information (usernames, passwords) . When a user logs in, values in a table in another database is to be updated.

How could this be achieved ?

[edit]

Sorry, yes, the two different databases are on the same database server.

[Updated]

I have mainDB.users table :

username | password | NumberLogins
---------|----------|--------------
         |          |

and a otherDB.history table :

username | points
---------|---------
         |

How do we increment the corresponding points after a user has logged in ?

USE `mainDB`;

DROP TRIGGER IF EXISTS `updateUserInfo`;

DELIMITER ||

CREATE TRIGGER `updateUserInfo` 
    BEFORE UPDATE ON `users` 
    FOR EACH ROW

    BEGIN
        IF NEW.`NumberLogins`=5 THEN

            UPDATE `otherDB`.`history`
            SET `points` = `points` + 1,
            WHERE 
              `username`=NEW.`username`;

        END IF;

    END ||

I keep getting this error.

 #1442 - Can't update table 'history' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. 
  • 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-13T17:22:06+00:00Added an answer on June 13, 2026 at 5:22 pm

    I assume both DBs are on the same server.

    USE name_of_db_trigger_to_be_in;
    delimiter ||
    create trigger.......
    
       UPDATE other_db.other_table
       SET other_guys = 'hohoho';
    
    
    end||
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a trigger that monitor changes on a table and then
How could i create a trigger that at any insertion on my table [users]
I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
is is possible in postgres to have a trigger on CREATE TABLE that will
I want to create a trigger that execute on update of a table. in
I'd like to create a trigger that writes to a history table with inserted
I'd like to create a before insert trigger that uses new values to insert
I'm trying to create a fairly simple trigger that would add one to a
I have a table in a SQL Server 2005 database with a trigger that
I'm working with wordpress and need to create a trigger that updates a table

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.