dqjo4340 2015-12-13 04: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 04: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部