我如何存储工作时间? [英] How do I store Work Time?

查看:108
本文介绍了我如何存储工作时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧

我想知道在SQL Server中存储员工工作时间的最佳数据表结构。

谢谢

解决方案

我只是想用一个简单的样本来问它,实际上我想发一条消息因为一个事件,现在我想,用户可以确定何时应该发生这个事件。

哪个月,

当天,

当天的时间,


In在哪种情况下,您应该关注的唯一数据类型是DATETIME。没有其他商店持有月份和时间信息。

如果您正在寻找重复值 - 每3个月,2天14:00或每月3日16:00 那么你需要考虑手动存储所有元素而不是更复杂的处理 - 因为SQL DATEADD一次只能处理一种类型的增量。


你可以存储startdatetime和enddatetime每个员工,然后通过每个日期的时差,您可以获得所有员工每天的工作时间。即大多数组织通常使用的内容





如果你有办法识别它,你可以添加其他列,如breaktime 。


试试吧。



 创建  Work_Assign_Employee 

[Id] [ bigint ] < span class =code-keyword> IDENTITY ( 1 1 NOT NULL
[Employee_id] [ varchar ]( 50 NOT NULL
[Work_id] [ varchar ]( 50 NOT NULL
[日期] [日期] NULL 默认(getdate()) ,
[时间] [时间]( 7 NULL


添加更多 如果你想要




ALTER TABLE [dbo]。[Work_Assign_Employee] WITH 检查 ADD CONSTRAINT [FK_Employee] FOREIGN KEY ([Employee_id])
REFERENCES [dbo]。[Employee_Master]([Employee_id])



ALTER TABLE [dbo]。[Work_Assign_Employee] WITH CHECK ADD CONSTRAINT [FK_Wokr] FOREIGN KEY ([Work_id])
REFERENCES [dbo]。[Work_Master]([Work_id])


Hi every body
I want to know the best data table structure of storing an employee work time in SQL Server.
Thanks

解决方案

"I just ask it with a sample to simple imagine, actually I want to sent a message because of an event, now I want to, user can determine when this event should be happened.
which Month,
which Day,
which Time of Day,"

In which case, the only datatype you should be looking at is DATETIME. No other store holds month and time info.
If you are looking to a repeat value though - "every 3 months, 2 days at 14:00" or "every 3rd of the month at 16:00" then you need to look at storing all the elements manually and rather more complex processing - as SQL DATEADD can only cope with one type of increment at a time.


You could store startdatetime and enddatetime by each employee and then by taking time difference by each date you can get the working hours of each day of all employee. i.e. what is generally used by most of the organisation


You can add other columns also like breaktime if you have a way to identify it.


Try it.

Create Table Work_Assign_Employee
(
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Employee_id] [varchar](50) NOT NULL,
[Work_id] [varchar](50) NOT NULL,
[Date] [Date] NULL Default(getdate()),
[Time] [Time](7) NULL
.
.
add more column if you want

)


ALTER TABLE [dbo].[Work_Assign_Employee]  WITH CHECK ADD  CONSTRAINT [FK_Employee] FOREIGN KEY([Employee_id])
REFERENCES [dbo].[Employee_Master] ([Employee_id])



ALTER TABLE [dbo].[Work_Assign_Employee]  WITH CHECK ADD  CONSTRAINT [FK_Wokr] FOREIGN KEY([Work_id])
REFERENCES [dbo].[Work_Master] ([Work_id])


这篇关于我如何存储工作时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆