Search code examples
mysqlsqldrop-table

extra column in MySQL, can I drop it?


I have a database I'm creating and I made a 1 to 1 connection with another table in Mysql, below is a screen shot. My question is can I drop the extra column (assembly factory_id) that was created when I made the connection? I only want the single (factory_id) will this mess up the connection that I made? Should i drop the (factory_id) and let the connection stay? I'm a noob, thanks!

enter image description here


Solution

  • I am assuming that your comment "but should i drop the table?" really meant to say "but should i drop the column?".

    Short answer: if it is safe, you should delete the column - there's no reason to keep it cluttering up the database and the minds of future developers.

    Long answer: how to determine if it's safe: If 1) the value in factory_id IS and ALWAYS WILL BE identical to assembly factory_id, eg, they are a duplicate value of each other, and 2) no other tables or program code refer to assembly factory_id, you can safely delete assembly factory_id.

    However, if there's any chance that they ever mean different things (not just the sample of 20 or so rows), you can't delete it. See fiddle: http://sqlfiddle.com/#!9/0bf17/1

    If they are always the same, but parts of the database or the code refer to assembly factory_id, you can refactor those database or code parts to refer to factory_id instead and THEN delete assembly factory_id.

    When doing something like this, you should make tests to verify that the state of queries and programs after the change is the same as the state before the change.