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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:56:03+00:00 2026-05-25T20:56:03+00:00

I have imported an excel document into MySQL to tidy up and make better

  • 0

I have imported an excel document into MySQL to tidy up and make better use of the data but I am having problems running an update.

All tables used as examples below;

Tables
asset_register
phone
sim
team

The asset_register contains the following cols;

id INT,
serialNo VARCHAR,
simNo INT,
team VARCHAR

The problem is that I want to create a team table and the reference the teamId in the asset_register table.

Does that make sense? Instead of storing the actual team name i want a foreign key to the teams table.

The problem lies in updating all the data in the asset_register table which was imported from excel. There are nearly the same no of teams as users (~500) and I need to write a query or Stored Procedure to update all of them.

I thought that a stored procedure would be the way to go. So far i have the following but it updated the value of team to ‘NULL’ instead of the teamId.

    DELIMITER //
    DROP PROCEDURE `updateCrews`//
    CREATE DEFINER=`root`@`localhost` PROCEDURE `updateCrews`()

    BEGIN

DECLARE rowCount INT;
DECLARE crewNameFromRegister VARCHAR(7);
DECLARE currentRow INT;
DECLARE newCrewdata VARCHAR(7);

SET rowCount=(SELECT COUNT(*) FROM asset_register);
SET currentRow = 1;

myUpdateLoop: WHILE (currentRow < rowCount) DO

    SET crewNameFromRegister = (SELECT crewID FROM asset_register WHERE id = currentRow);   
    SET newCrewData = (SELECT id FROM crews WHERE crewName = crewNameFromRegister);
    UPDATE asset_register SET crewID = newCrewData;

    SET currentRow = currentRow + 1;

END WHILE myUpdateLoop;

    END//

    DELIMITER ;

Any help would be greatly appreciated, there is probably a better way to do this and a nudge in the right direction would be great.

  • 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-25T20:56:04+00:00Added an answer on May 25, 2026 at 8:56 pm

    If I good understand your question I suggest you to use a mutli table update syntax describe in mysql manual in this article : MutliTableUpdate. You try to change a string key by an id, be carreful of data type / conversion.

    The idea should be:

    UPDATE asset_register, crews
    SET    asset_register.crewID = crews.id
    WHERE  crews.crewName = asset_register.crewID 
    

    But it could be safer if you use an other column column to do it and check the intermediate result.

    On your first example:

    id INT,
    serialNo VARCHAR,
    simNo INT,
    team VARCHAR
    

    you can add a teamID column, do the update and rename your column

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

Sidebar

Related Questions

I have data imported from an excel sheet into a table in db. Now
I have a set of data which needs to be imported from a excel
I have a mysql query that pulls into excel via an ODBC connection. This
I have an Excel document with 10000 rows of data in two sheets, the
I have an Excel file (which has data imported from Oracle 10G Database) one
I have imported my .h file into a 2nd one, but in the 2nd
I have a beginners question in T-SQL. We imported Excel Sheets into a SQL
I have a large table I imported from an Excel spreadsheet. For five of
I have imported the kernel32 library. So, I have the createMutex function available but
I have imported an animated GIF as a resource into a picturebox - unfortunitly

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.