1

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

beau8008
  • 49
  • 1
  • 7

2 Answers2

1

You can drop the extra column by using the Alter statement.

ALTER TABLE table_name DROP COLUMN factory_id;

You can also refer to http://docs.oracle.com/cd/E18283_01/server.112/e17118/statements_3001.htm#i2103683 (Drop column clause in particular)

Edit: As far as the connection is concerned, the Alter statement dumps to a temporary table and then rebuilds without losing any connection. Please refer to the section Storage, Performance, and Concurrency Considerations in this document

shark1608
  • 649
  • 11
  • 24
1

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.

CindyH
  • 2,986
  • 2
  • 24
  • 38