0
我已經命名爲更新彙總表
PROD_DET
(ID , PROD_SUMM_ID, TRANS_DATE, EMP_ID, PROC_ID , PCS)
和
PROD_SUMM
(ID , TRANS_DATE, EMP_ID, PROC_ID , PCS)
現在,每當一個記錄插入PROD_DET表2桌,
我想Insert
(如果唯一的TRANS_DATE,EMP_ID,PROC_ID的記錄不可用)/ Update
(在記錄唯一的TRANS_DATE,EMP_ID,PROC_ID的情況下在我PROD_SUMM
表可用),
從PROD_DET獨特TRANS_DATE 表應放入PROD_SUMM表TRANS_DATE,
獨特EMP_ID和獨特PROC_ID應該進入他們的 各列 在PROD_SUMM表
- 的particluar TRANS_DATE的多個記錄PCS的總和應在 PCS列更新PROD_SUMM表 從PROD_SUMM表
- ID應該 PROD_DET表
我已經嘗試了與觸發器,但升級到PROD_SUMM_ID列,並沒有來到大關, 在下面找到
腳本的截圖箱表 ~~~~~~~~~~~~~~~~~~~~~~
CREATE TABLE [dbo].[PROD_DET](
[ID] [int] IDENTITY(1,1) NOT NULL,
[PROD_SUMM_ID] [int] NULL,
[TRAN_DATE] [date] NOT NULL,
[EMP_ID] [int] NOT NULL,
[PROC_ID] [int] NOT NULL,
[PCS] [smallint] NOT NULL,
CONSTRAINT [PK_PROD_DET] PRIMARY KEY CLUSTERED
([ID] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
CREATE TABLE [dbo].[PROD_SUMM](
[ID] [int] IDENTITY(1,1) NOT NULL,
[TRAN_DATE] [date] NOT NULL,
[EMP_ID] [int] NOT NULL,
[PROC_ID] [int] NOT NULL,
[PCS] [int] NOT NULL,
CONSTRAINT [PK_PROD_SUMM] PRIMARY KEY CLUSTERED
([ID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]