Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I wanted to know how one would go about doing the following using mysql.

If i have a table that has data inserted into it. I need to check data, then i need the data to be inserted into other tables in the same database.

For example:

Table 1
ID Name Telephone Address

When a row is inserted into that table. I need

Table 2
ID Telephone

to have the telephone number that was just inserted into table 1 to be inserted into table 2 as well. would triggers work here or are triggers just a way to run checks on data pertaining to the table the trigger was associated with?

Please someone help, i hope i have made sense in my request.
Posted
Comments
Mohibur Rashid 9-Sep-12 20:59pm    
Well, I think you are not using mysql alone. You are also using either php or c/c++ or some other front end language. why dont you execute two insert query?
Vedangi 10-Sep-12 2:14am    
You can use Trigger where ON insert in Table 1 , you can insert data into Table 2. You can check data in Trigger using NEW.ColumnName , if true then insert into Table 2 else Exit.
Ashy-G 25-Sep-12 16:31pm    
Thanks Vedangi, that works well, much appreciated
markkuk 10-Sep-12 5:37am    
Your tables are incorrectly designed. The right way to fix your problem is to make sure the telephone number is stored only in one place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900