How to load values of one table to another automatically in MySQL..?
there is a existing table 开发者_运维技巧A. suppose i want to add all or specific(column) values of an existing table A to table B using foreign key, how do i do it in MySQL? and if there is any new insert or update in table A it should automatically insert into table B also..
To automatically update Table B from changes in Table A would require triggers that MySQL supports but phpMyAdmin does not. If instead you're looking to insert rows into Table B from Table A on an ad-hoc basis then that's simple
INSERT INTO TABLEA (COL1, COL2, COL3)
SELECT FROM TABLEB (COL1, COL2, COL3)
WHERE (SELECT COUNT(*) FROM TABLEA WHERE TABLEA.COL1 = TABLEB.COL1) = 0
The above SQL does a simple copy from TableB into TableA. The WHERE clause ensures only records which don't already exist are inserted.
You can use insert/update trigger for that.
Why should you want to do that? Why don't you just reference the data in table A using the forign key in table B you mentioned?
insert into tableb(columns) select columns from tablea
精彩评论