简体   繁体   English

MySQL数据库一对一关系

[英]MySQL database one-to-one relation

If I have a database with multiple tables all with one to one relations. 如果我有一个包含多个表的数据库,它们之间都是一对一的关系。 What is the best approach for when I register a row in one table, it's also registers a row across the related tables. 当我在一个表中注册一行时,最好的方法是在相关表中也注册一行。 I know you can use cascade to update and delete using foreign keys so is there a similar approach for creating these related rows with default values? 我知道您可以使用级联来使用外键更新和删除,因此是否存在类似的方法来使用默认值创建这些相关行?

Creating null rows is not great design. 创建空行不是一个好的设计。 Better create them only when necessary using foreign keys. 最好仅在必要时使用外键创建它们。 If you still must, look at transactional stored procedures. 如果仍然需要,请查看事务存储过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM