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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:52:24+00:00 2026-06-03T07:52:24+00:00

I have a MySQL table for storing details of uploaded files, like this: CREATE

  • 0

I have a MySQL table for storing details of uploaded files, like this:

CREATE TABLE files (
    file_id bigint not null primary key auto_increment,
    file_name text,
    file_path text,
    file_extension varchar(15),
    file_link text);

The actual name of the file on the disk is set to the file_id generated by the table when I insert the record – so although I can record all sorts of details, the database doesn’t actually know what the file is called at this point.

Sure it’s easy to just run another UPDATE statement shortly after to set the file_link column, but I wondered if there was a way to do something a bit more elegant here?

What I would like to do is have the value of file_link be automatically set on INSERT to this: CONCAT(file_path, file_id, file_extension) without needing to run another UPDATE statement immediately after.

Does anyone know how I can do this – and if it’s a bad idea can you explain why?

P.S I’m using PHP to run these statements, if that makes a difference.

  • 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-03T07:52:26+00:00Added an answer on June 3, 2026 at 7:52 am

    You could do this with the following trigger:

    DELIMITER $$
    
    CREATE TRIGGER makelink BEFORE INSERT ON files
      FOR EACH ROW
        BEGIN
          SET NEW.file_link = CONCAT(NEW.file_path, NEW.file_id, NEW.file_extension);
        END;
    $$
    
    DELIMITER ;
    

    …although I have to say, I personally would go with creating this with the SELECT statement instead of having the database do things like this on insert – sure it’s slightly more efficient to store static data, but it makes the database schema less transparent.

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

Sidebar

Related Questions

I have a simple MySQL table for storing notification in a web with social
I have a MySQL table, in which I will be storing the email_id of
I am using mysql and have a table (Log_Table) storing user login dates, a
In a mysql MyISAM table, I have a column type mediumblob and storing captured
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySQL table and would like to return the rows based on
I have a MySQL database table that has a VARCHAR field storing a date
I have mysql table that has a column that stores xml as a string.
I was thinking that I would have two tables for mysql. One for storing
I have a MySql table containing stock quotes (stock_symbol, quote_date, open_price, high_price, low_price, close_price)

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.