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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog