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条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料