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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:13:20+00:00 2026-06-14T18:13:20+00:00

Is there a way to restrict insert or update to specific columns in a

  • 0

Is there a way to restrict insert or update to specific columns in a table using innodb engine in MySQL? I want to update these columns only through triggers or procedures

What I want to do is to calculate these columns automatically and not allow the change of these directly. Let me know if my approach is not correct

  • 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-14T18:13:22+00:00Added an answer on June 14, 2026 at 6:13 pm

    Let me know if my approach is not correct

    Your approach is unusual, but not impossible. Whether it is “correct” will depend on factors not mentioned in your question:

    • If the columns are always the result of some simple expression, you could simply specify that expression in each SELECT:

      SELECT col_a, col_b, LEAST(10*col_a, 5*col_b) AS calculated_column
      FROM   mytbl
      WHERE  ...
      

      Or store the results in a view so that you don’t need to write the expression(s) every time:

      CREATE VIEW myview AS
      SELECT col_a, col_b, LEAST(10*col_a, 5*col_b) AS calculated_column
      FROM   mytbl
      

      In which case, to select the results one merely need do:

      SELECT * FROM myview WHERE ...
      

      However, note that calculated_column will still be evaluated each time you select from the view, so could lead to performance problems if it’s a complicated expression or your table is large. If instead you want to store the result of the calculation (so that it need not be evaluated on each SELECT), you could define triggers that overwrite any value supplied by the user:

      CREATE TRIGGER mytbl_insert AFTER INSERT ON mytbl FOR EACH ROW SET
        NEW.calculated_column = LEAST(10*NEW.col_a, 5*NEW.col_b);
      
      CREATE TRIGGER mytbl_update AFTER UPDATE ON mytbl FOR EACH ROW SET
        NEW.calculated_column = LEAST(10*NEW.col_a, 5*NEW.col_b);
      
    • If the columns will actually be periodically updated, but only from a stored procedure:

      1. Deny your existing user(s) permission to update the columns:

        REVOKE INSERT (col1, col2), UPDATE (col1, col2) ON mydb.mytbl FROM myuser;
        

        Note that if your user has table- or database-level privileges, they will need to be revoked and replaced with column-level ones as appropriate.

      2. Create a user under which the procedure will run:

        GRANT INSERT, UPDATE ON mydb.mytbl TO
        'procuser'@'nonexistent' IDENTIFIED BY PASSWORD '';
        
      3. Define your procedure to run under that new user:

        CREATE DEFINER = 'procuser'@'nonexistent' PROCEDURE ...
        
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Jenkins, is there a way to restrict certain jobs so that only specific
Sorry for this silly question, but is there any way to restrict using directives
Is there a way to restrict a method to only take certain members of
Is there any way I can restrict a user to select files from only
Is there a way to restrict this button to only being impressed once? The
Is there a way to restrict the installation of my app to allow only
Is there a way to restrict access to a specific webpage such as http://www.example.com/subpage
Is there a way to restrict a user to enter only certain information inside
Is there a way to restrict view rotation to only one view controller? For
Is there any way to restrict that only 2 digits can enter in 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.