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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化