If multiple tables have the same fields, what is a good way to do synchronous updates? For example, the user name field of the order data table, the user mobile number field, needs to be updated as the field of the user table is updated
Programming
Collapse
X
-
Hello Livre
Welcome to Bytes...
You've provided precious little for us to work with, are the relationships setup between the tables on these fields, etc...
Take a look at MySQL UPDATE Statement
See if that's on the right path.... personally I've never had to update across multiple tables with a mysql database... (read on to see why)
However, from what you do provide, at first read, it sounds to me like your database is not normalized (see link)
> Database Normalization and Table Structures.
If this is the case, your very first step SHOULD be to start normalizing your database - it is a pain, it is well worth every second you put in to do so as a DBA because doing so will save weeks and months of time in developing views/queries and maintaining the overall data integrity.
Normalizing your data would make updates like what I think you asking about very simple; for example (please ignore spelling):
Code:[iCODE][highlight]VERY Simple Example[/highlight][/iCODE] [iCODE][tbl_employ][/iCODE] [PK_Customer][FamilyName][FirstName] [1 ][Doe ][John ] [2 ][Smith ][Shellie ] [iCODE][tbl_Telephone][/iCODE] [PK_Info][FK_Employ ][Telephone] [1 ][1 ][555-555-0001] [2 ][1 ][555-555-0002] [3 ][1 ][555-555-0003] [4 ][2 ][555-555-9001] [5 ][2 ][555-555-9002] [6 ][2 ][555-555-9003]
"FK " indicates a foreign key which points back to a record in a related table
The relationship is one-to-many between[tbl_employ]
and[tbl_Telephone]
on the fields
[tbl_employ]![PK_Customer]
and[tbl_Telephone]![FK_Employ]
(if you don't understand this, please see the link above covering normalization)
Say we publish a report with each employ's name and telephone numbers and "Shellie" informs us that the first name is misspelled and should be "Shelly"!
Now with a normalized database we only need to go to[tbl_employ]
and edit one record and reprint.
HOWEVER
Say that in[tbl_Telephone]
we had added fields for[FamilyName]
and[FirstName]
then we would not only have to edit the record in[tbl_employ]
but also three records in[tbl_Telephone]
Comment