dqjo4340 2015-12-13 12:04
浏览 146
已采纳

在mysql数据库中存储未知大小的数组

Hi I have in mysql database a datetime value (2015-01-01 12-54-32) which I use to know the date in which the library subscriber reserved a book it is easy to store one datetime value in database but the problem is i don't know how many books the subscriber will reserve from the library could be 1 or could be 5 , the question is how do i store it in database as array ?

  • 写回答

3条回答 默认 最新

  • duanchu7271 2015-12-13 12:15
    关注

    The correct way to store this in a database is to use a junction table. Something like this:

    create table BookReservations (
        BookReservationId int auto_increment primary key,
        SubscriberId int not null,
        BookId int not null,
        ReservationDate date not null,
        constraint fk_bookreservations_subscriberid foreign key (SubscriberId) references Subscribers(SubscriberId),
        constraint fk_bookreservations_bookid foreign key (BookId) references Books(BookId)
    );
    

    (Clearly, this just suggests names for entities and columns not mentioned in the question.)

    Note that this table defines the foreign key relationships among the tables as well as storing the data. This allows the database to ensure relational integrity. MySQL does not (currently) allow such definitions for string or JSON objects.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 vue2(标签-chrome|关键词-浏览器兼容)
  • ¥15 python网络流自动生成系统 医学领域
  • ¥15 sql查询仓库里都有什么
  • ¥15 代码的修改,添加和运行完善
  • ¥15 krpano-场景分组和自定义地图分组
  • ¥15 lammps Gpu加速出错
  • ¥15 关于PLUS模型中kapaa值的问题
  • ¥15 关于博途V17进行仿真时无法建立连接问题
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器