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.
首先,这个问题可能会产生误导,因为我不知道如何将我的确切问题置于文字中。 p>
我打算建立一个用户能够进入/超时的考勤系统。 我创建了两个表,首先是用户表(包含用户的信息)和时间戳表(包含进入时间和超时)。 现在问题是我不知道如何实现时间戳表连接到特定用户,并能够存储多个时间输入和超时。 p>
请让我 知道是否需要澄清一些事情我不确定我提供的信息是否足够。 提前致谢。 p> div>
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`)
);