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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:21:25+00:00 2026-06-10T07:21:25+00:00

I am trying to write a before delete trigger on mysql table here’s is

  • 0

I am trying to write a before delete trigger on mysql table here’s is what I am trying to do exactly; I need a specific record to always be in the table so say for example the record is deleted or updated the trigger would simply reinsert the initial record.

EXAMPLE
Tablename: Users
Table Columns(3):ID,Username,Password
and I am trying to keep the following record from being deleted(Initial Record)
Username=Dames, Password=Password

However Im new to triggers and have been trying a thing or 3 but it really seems I need some help, I hope I made the question clear, and thanks alot.

  • 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-10T07:21:26+00:00Added an answer on June 10, 2026 at 7:21 am
    1. If you’re happy to hard-code into the triggers the details of the record that you wish to preserve, then you could do something like:

      DELIMITER ;;
      
      CREATE TRIGGER foo_upd BEFORE UPDATE ON Users FOR EACH ROW
      IF OLD.Username <=> 'Dames' AND OLD.Password <=> 'Password' THEN
        INSERT INTO Users (Username, Password) VALUES ('Dames', 'Password');
      END IF ;;
      
      CREATE TRIGGER foo_del BEFORE DELETE ON Users FOR EACH ROW
      IF OLD.Username <=> 'Dames' AND OLD.Password <=> 'Password' THEN
        INSERT INTO Users (Username, Password) VALUES ('Dames', 'Password');
      END IF ;;
      
      DELIMITER ;
      
    2. Otherwise, I’d recommend adding an additional boolean column to the Users table—e.g. locked:

      ALTER TABLE Users ADD COLUMN locked BOOLEAN NOT NULL DEFAULT FALSE;
      

      Then setting the value of that column to be TRUE on the record(s) that you wish to preserve:

      UPDATE Users SET locked = TRUE
      WHERE  Username = 'Dames' AND Password = 'Password';
      

      Then creating triggers along the following lines:

      DELIMITER ;;
      
      CREATE TRIGGER foo_upd BEFORE UPDATE ON Users FOR EACH ROW
      IF OLD.locked THEN
        INSERT INTO Users (Username, Password) VALUES (OLD.Username, OLD.Password);
      END IF ;;
      
      CREATE TRIGGER foo_del BEFORE DELETE ON Users FOR EACH ROW
      IF OLD.locked THEN
        INSERT INTO Users (Username, Password) VALUES (OLD.Username, OLD.Password);
      END IF ;;
      
      DELIMITER ;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write to a plist file using writeToFile, before I write I
I'm trying to write my own C++ String class for educational and need purposes.
I am trying to write a RSpec before filter to log a user in.
I'm trying to write a simple decorator that logs a given statement before calling
I am trying to write a trigger function in PostgreSQL 8.2 that will dynamically
I'm trying to write some tests around some code previously written before I start
I'm trying to write a jQuery script (I have never written one before and
do there any dev who wrote iPhone wifi/bluetooth multiplay before? Recently, I'm trying to
I am trying write a script where when a user clicks on a link,
I m trying write code that after reset set up rrpmax as 3000. It

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.