0

I am trying to update a table where it has a network_name ,say the LOAD table. Table Network has the same column too, network_name. Now how will I update the values on table LOAD if the same value was updated on table Network?

LOAD

network_name | product code |
-------------+--------------+
Talk & Text  | aaaaaaaaaaa
Talk & Text  | aaaaaaaaaaa
Touch Mobile | aaaaaaaaaaa

NETWORK

network_id |network_name | network code |
-----------+-------------+--------------+
12235      |Talk & Text  | aaaaaaaaaaa
23343      |Smart        | aaaaaaaaaaa
34343      |Touch Mobile | aaaaaaaaaaa

Now what if the Talk N Text is changed into TalkText, how will I update the Load table?

2
  • UPDATE [LOAD] SET [network_name] = 'TalkText' WHERE [network_name] = 'Talk & Text' ? It's not clear what the problem is or why you can't update the data. Commented Mar 5, 2014 at 16:44
  • 2
    I recommend you read up on database normalization - Rather than storing the verbatim text in each database record, you can store a link to the text that each record should use. This way, if you need to change Talk & Text to TalkText, you only need to update one place. Commented Mar 5, 2014 at 16:46

2 Answers 2

1

Add a primary/ID column to Load:

load_id | network_name   |  product_code |
--------+----------------+---------------+
0       | talk & text    | aaaaaaaaaaaa  |
1       | touch & mobile | aaaaaaaaaaaa  |
2       | smart          | aaaaaaaaaaaa  |

Reference load_id from NETWORK:

network_id | load_id  |  network_code |
-----------+----------+---------------+
12235      | 0        | aaaaaaaaaaaa  |
23343      | 2        | aaaaaaaaaaaa  |
34343      | 1        | aaaaaaaaaaaa  |

Apply all updates to Load and use a SQL to link your results.

Sign up to request clarification or add additional context in comments.

Comments

0

In a normalized database, network_name doesn't really belong in the LOAD table as it's data related to a NETWORK entity.

If the LOAD table needs to have a relationship with the NETWORK table, then instead of having a network_name column in the LOAD table, use a network_id column instead.

Now you only have to update the NETWORK table if the network_name changes but the LOAD and NETWORK tables still have a relationship with each other.

If you want to normalize further then you could add a load_id column to the LOAD table, remove the network_id from the LOAD table and then create a new table which holds just the relationships between NETWORK and LOAD (i.e. a table with a network_id and load_id column) but whether you do that or not is down to your problem domain.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.