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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试