向一个表插入数据的同时写入数据到另外一个数据库表(触发器)

create TRIGGER tr_testUser
   ON  oa2016.dbo.IBP_T_User
  FOR INSERT
AS 
BEGIN

    SET NOCOUNT ON;

    INSERT INTO test.dbo.EmpInfo(sName,sEmpNo)
    SELECT sName,sEmp_ID FROM INSERTED
    
  --INSERT INTO TonyLink.oa2016_SKU.dbo.ibp_t_user(sName,sEmp_ID)
  --  SELECT sName,sEmp_ID FROM INSERTED
END
GO

create TRIGGER tr_testData
   ON  test.dbo.mj_mjdata
  FOR INSERT
AS 
BEGIN

    SET NOCOUNT ON;

    INSERT INTO oa2016.dbo.HR_KQ_T_Origin(FK_MachineID,FK_HandID,FK_UserID,FK_WorkNo,dWKTime,sUserHostAddress,bNeedAnalysis)
    SELECT '0',0,ISNULL(u.pk_id,0),ISNULL(u.sEmp_ID,''),dWKTime=CONVERT(NVARCHAR(100),i.logDate,23)+' '+test.dbo.GetTimeStr(i.logtime),'',0 FROM INSERTED i LEFT JOIN rs_Emp emp ON i.empsysId=emp.empsysid LEFT JOIN oa2016.dbo.ibp_t_user u ON u.semp_id=emp.empno 
    

你可能感兴趣的:(基础知识)