开发者

How can I insert a row in all tables in a database?

开发者 https://www.devze.com 2023-03-16 06:15 出处:网络
I haven\'t been able to find an easy solution for this but I\'m pretty sure there is somewhere. How can I add a row to all tables in a database?

I haven't been able to find an easy solution for this but I'm pretty sure there is somewhere. How can I add a row to all tables in a database?

For instance if I had two tables A and B how can I add (insert?) row C into both tables?

EDIT: All of the 开发者_运维百科tables have the same structure.


There is no statement that will insert into more than one table at the same time.

You will have to find out the table names that you want to insert data into, and issue an insert statement for each of them. You can do that within a single transaction, though.

Also note that usually different tables in the database have different schema, so that you may not be able to insert the exact same row into all of them.

Also note that there is an influential school of relational database designers that tries to avoid duplication (because it wastes storage and can lead to inconsistencies when later updates are not applied properly). They would not like the idea of storing the same piece of data in multiple locations.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号