如何将一个表数据插入到第一个表中的另一个表中,另一个表是默认的 [英] How to insert one table dataes to another table one filed from first table and another is default
本文介绍了如何将一个表数据插入到第一个表中的另一个表中,另一个表是默认的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张桌子
表:员工
I have two tables that are
Table : Employee
Emp_Id | Emp_name
--------------|-----------------
1 | boy
2 | arun
3 | suresh
4 | saju
表:出勤率
Table: Attendance
Emp_Id| date |status
------|----------|---------
1 |10/03/2013| P
2 |10/03/2013| P
3 |10/03/2013| P
4 |10/03/2013| P
当事件发生时
插入考勤表Emp_Id从员工表日期和状态是默认的
哪个sql查询我可以用于此
When Event occurs
insert into Attendance table Emp_Id from Employee table date and status is default
which sql query can I use for this
推荐答案
您好,
查看此
如何在一个商店程序中将数据插入多个表? [ ^ ]
或者您可以使用触发器
http://msdn.microsoft.com/en-us/library/ms189799.aspx [ ^ ]
最好的问候
M.Mitwalli
Hi ,
Check this
how can i insert data in multiple table in one store procedure?[^]
or you can useTrigger
http://msdn.microsoft.com/en-us/library/ms189799.aspx[^]
Best Regards
M.Mitwalli
通过添加默认约束,您可以实现这个目标。
By adding default constraint you can achieve this goal.
ALTER TABLE Attendance
ADD CONSTRAINT df_Constraint_Attendance_Date
DEFAULT GETUTCDATE() FOR [Date]
GO
ALTER TABLE Attendance
ADD CONSTRAINT df_Constraint_Attendance_Status
DEFAULT 'P' FOR [Status]
GO
---Example
INSERT INTO Attendance (Emp_Id) VALUES(1)
这篇关于如何将一个表数据插入到第一个表中的另一个表中,另一个表是默认的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文