duanmeng9336 2014-07-02 22:45
浏览 42
已采纳

SQL:如何在sql中为特定表实现多个数据的插入/更新

First of all the question might be misleading for I don't know how to put into words my exact problem.

I'm planning to make an attendance system where a user would be able to time-in/time-out. I created two tables, first the user table(containing user's information) and the timestamp table(containing the time-in and time-out). Now the problem is I don't know how to implement the timestamp table to be connected to a specific user and be able to store multiple time-ins and time-outs.

Please let me know if need to clarify some things for I'm not sure if the info I've given is enough. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dqp4933 2014-07-02 22:58
    关注

    Add a unique user identifier column to the user table and make it your primary key. Add the same column to the attendance table but do not make it a primary key. It will be this common column that will allow you to relate your users to their attendance. You may also want a unique identifier on the attendance table if you are not going to set the time out until later.

    CREATE TABLE  `User` (
        `UserID` int unsigned NOT NULL auto_increment,
        PRIMARY KEY  (`UserID`)
    );
    
    CREATE TABLE `UserAttendance` (
        `UserID` int unsigned NOT NULL,
        `InTimestamp` timestamp NOT NULL,
        `OutTimestamp` timestamp NULL,
        FOREIGN KEY (`UserID`)
            REFERENCES `User`(`UserID`)
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)