SQL Copy values from one table to another | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

SQL Copy values from one table to another

Hi! I just finished the SQL course and there is one thing that I need and it is not specified. How can I set up a dynamic column values copy from one table column to another? For example I´ve got tables: STUDENTS with columns ID, NAME, LASTNAME, AGE, NOTE EXAMS with columns ID, SUBJECTS, NOTE The column NOTE from EXAMS table will be updated assiduously and I need to update the NOTE column from STUDENTS with the same values each time there is a change. Is it possible? Thank you in advance! :)

5th Apr 2020, 5:38 PM
Mikel Barron
Mikel Barron - avatar
3 Answers
+ 2
Depending on which DBMS you use, you can set up a Trigger script on the EXAMS table that automatically updates STUDENTS.NOTES whenever EXAMS.NOTES changes. Stepping back a level in perspective, it is against good DB design to maintain the same data in multiple places. Consider rebalancing your tables so NOTES gets stored in one table (perhaps its own separate table) and is linked by reference keys.
5th Apr 2020, 9:17 PM
Brian
Brian - avatar
+ 1
Hi Brian! Thank you for your reply! The problem is that the ERP of the company is sending "notes" to another table and I can't chage anything in this soft. In the other side there is an eccomerce. I'm going to try with a trigger as you say :)
5th Apr 2020, 9:59 PM
Mikel Barron
Mikel Barron - avatar
+ 1
Now I understand. Yes, a trigger is a good solution in this case. Glad I could help. 😌
5th Apr 2020, 10:07 PM
Brian
Brian - avatar