› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
yueqianzhang
V2EX  ›  MySQL

mysq 问个数据库方面的简单问题

  •  
  •   yueqianzhang · Mar 15, 2020 · 3656 views
    This topic created in 2388 days ago, the information mentioned may be changed or developed.

    比如说有两个表,Customer 和 Vehicle (用户表和车型表)

    每个 Customer 只有一个 Vehicle,又不想让 Vehicle 表包含 CustomerID 字段,(因为想把 Vehicle 表只当一个查询的表,每个车型只有一条记录)

    1. 怎么设计比较好,Customer 持有 VehicleID 字段吗?
    2. 怎么用 GORM 写比较好(最好能直接点出来包含的 Vehicle 的属性
    5 replies  •  2020-03-15 12:38:16 +08:00
    brucefu
        1
    brucefu  
       Mar 15, 2020
    Customer 持有 Vehicle ID
    rekulas
        2
    rekulas  
       Mar 15, 2020   ❤️ 2
    按常规设计应该加一个 mapping(映射)表
    但如果确定只有一条的话而且以后也不大可能更改的话按一楼说的要简单点效率也高点
    LightLolo
        3
    LightLolo  
       Mar 15, 2020
    可以做个中间表 只有两个字段 CustomerID 和 VehicleID
    linuxvalue
        4
    linuxvalue  
       Mar 15, 2020
    Customer 持有 Vehicle ID +1
    Takamine
        5
    Takamine  
       Mar 15, 2020
    建议放一个中间表,这样之后要是可能扩展成 1:n 或者 n:1 都比较方便。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3288 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:04 · PVG 13:04 · LAX 22:04 · JFK 01:04
    ♥ Do have faith in what you're doing.