묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
mssql관련질문입니다. 도와주셔요 ㅠ
2004.08.17 12:19
CREATE TRIGGER trg_mug_new2
ON char_data
For update
AS
update char_data
set char_name = replace(i.char_name, '$C', '$B'), char_level=11, char_str=45, char_con=0, char_w1=0, char_w2=0, char_w3=0, char_w4=0, char_str_exp=0, char_con_exp=0, char_dex_exp=0, char_w1_exp=0, char_w2_exp=0, char_w3_exp=0, char_w4_exp=0, char_max_hit=(i.char_max_hit*0.6), char_hit=(i.char_hit*0.6), char_exp=0 , char_chk=2
from char_data c inner join inserted i on i.char_serial = c.char_serial
where i.char_level>=1500 and (i.char_str+
case when i.char_class=0 then i.char_w1
when i.char_class=1 then i.char_w2
when i.char_class=2 then i.char_w3
when i.char_class=3 then i.char_w4
end
)>=5000 and i.char_chk = 1
--------------------------------------------------------
사용된 트리거는 이것이구요.. 이트리거를 실행시키기위해
업데이트를 해보면 아래그림처럼 오류가뜨네용..
--------------------------------------------------------
--------------------------------------------------------
그리구 char_data 테이블의 속성은 이렇습니다..
--------------------------------------------------------
CREATE TABLE [dbo].[Char_Data] (
[Char_Serial] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Char_Account_Num] [int] NULL ,
[Char_Name] [nvarchar] (12) COLLATE Korean_Wansung_CI_AS NULL ,
[Char_Title] [varchar] (12) COLLATE Korean_Wansung_CI_AS NULL ,
[Char_Level] [smallint] NULL ,
[Char_Str] [smallint] NULL ,
[Char_Dex] [smallint] NULL ,
[Char_Con] [smallint] NULL ,
[Char_W1] [smallint] NULL ,
[Char_W2] [smallint] NULL ,
[Char_W3] [smallint] NULL ,
[Char_W4] [smallint] NULL ,
[Char_Str_Exp] [int] NULL ,
[Char_Dex_Exp] [int] NULL ,
[Char_Con_Exp] [int] NULL ,
[Char_W1_Exp] [int] NULL ,
[Char_W2_Exp] [int] NULL ,
[Char_W3_Exp] [int] NULL ,
[Char_W4_Exp] [int] NULL ,
[Char_Hit] [int] NULL ,
[Char_Max_Hit] [int] NULL ,
[Char_Mana] [int] NULL ,
[Char_Max_Mana] [int] NULL ,
[Char_Exp] [int] NULL ,
[Char_Class] [tinyint] NULL ,
[Char_Sex] [tinyint] NULL ,
[Char_Agi] [tinyint] NULL ,
[Char_Gold] [bigint] NULL ,
[Char_Age] [int] NULL ,
[Char_Last_Logon] [datetime] NULL ,
[Char_X] [smallint] NULL ,
[Char_Y] [smallint] NULL ,
[Char_Zone] [tinyint] NULL ,
[Char_Dir] [tinyint] NULL ,
[Char_Admin_Level] [tinyint] NULL ,
[Char_Flags] [int] NULL ,
[Char_Grade] [smallint] NULL ,
[Char_Ext] [int] NULL ,
[Char_CHK] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Char_Data] ADD
CONSTRAINT [DF_Char_Data_Char_Grade] DEFAULT (0) FOR [Char_Grade],
CONSTRAINT [DF_Char_Data_Char_Ext] DEFAULT (0) FOR [Char_Ext],
CONSTRAINT [DF_Char_Data_Char_CHK] DEFAULT (0) FOR [Char_CHK]
GO
------------------------------------------------------
결론을 말씀드리자면..트리거문에 for update 가아닌 instead of update 를 사용하면 잘작동하더라구요. 하지만 instead of update
를 사용하니 데이터값들이 증가하질않고 계속 원상복귀에요.
char_level을 예로들자면 트리거가작동해서 char_level = 11
이되고 또 업데이트이벤트가일어나면 char_level의 값이 증가하질않
는다는거죠. for update를 사용하면 저런오류가 뜨궁..휴.;;
혹시 replace 함수 때문인건가요.?
초보라 설명이 이상하네요..ㅠㅠ 해결책좀..부탁합니다.ㅠ
ON char_data
For update
AS
update char_data
set char_name = replace(i.char_name, '$C', '$B'), char_level=11, char_str=45, char_con=0, char_w1=0, char_w2=0, char_w3=0, char_w4=0, char_str_exp=0, char_con_exp=0, char_dex_exp=0, char_w1_exp=0, char_w2_exp=0, char_w3_exp=0, char_w4_exp=0, char_max_hit=(i.char_max_hit*0.6), char_hit=(i.char_hit*0.6), char_exp=0 , char_chk=2
from char_data c inner join inserted i on i.char_serial = c.char_serial
where i.char_level>=1500 and (i.char_str+
case when i.char_class=0 then i.char_w1
when i.char_class=1 then i.char_w2
when i.char_class=2 then i.char_w3
when i.char_class=3 then i.char_w4
end
)>=5000 and i.char_chk = 1
--------------------------------------------------------
사용된 트리거는 이것이구요.. 이트리거를 실행시키기위해
업데이트를 해보면 아래그림처럼 오류가뜨네용..
--------------------------------------------------------
--------------------------------------------------------
그리구 char_data 테이블의 속성은 이렇습니다..
--------------------------------------------------------
CREATE TABLE [dbo].[Char_Data] (
[Char_Serial] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Char_Account_Num] [int] NULL ,
[Char_Name] [nvarchar] (12) COLLATE Korean_Wansung_CI_AS NULL ,
[Char_Title] [varchar] (12) COLLATE Korean_Wansung_CI_AS NULL ,
[Char_Level] [smallint] NULL ,
[Char_Str] [smallint] NULL ,
[Char_Dex] [smallint] NULL ,
[Char_Con] [smallint] NULL ,
[Char_W1] [smallint] NULL ,
[Char_W2] [smallint] NULL ,
[Char_W3] [smallint] NULL ,
[Char_W4] [smallint] NULL ,
[Char_Str_Exp] [int] NULL ,
[Char_Dex_Exp] [int] NULL ,
[Char_Con_Exp] [int] NULL ,
[Char_W1_Exp] [int] NULL ,
[Char_W2_Exp] [int] NULL ,
[Char_W3_Exp] [int] NULL ,
[Char_W4_Exp] [int] NULL ,
[Char_Hit] [int] NULL ,
[Char_Max_Hit] [int] NULL ,
[Char_Mana] [int] NULL ,
[Char_Max_Mana] [int] NULL ,
[Char_Exp] [int] NULL ,
[Char_Class] [tinyint] NULL ,
[Char_Sex] [tinyint] NULL ,
[Char_Agi] [tinyint] NULL ,
[Char_Gold] [bigint] NULL ,
[Char_Age] [int] NULL ,
[Char_Last_Logon] [datetime] NULL ,
[Char_X] [smallint] NULL ,
[Char_Y] [smallint] NULL ,
[Char_Zone] [tinyint] NULL ,
[Char_Dir] [tinyint] NULL ,
[Char_Admin_Level] [tinyint] NULL ,
[Char_Flags] [int] NULL ,
[Char_Grade] [smallint] NULL ,
[Char_Ext] [int] NULL ,
[Char_CHK] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Char_Data] ADD
CONSTRAINT [DF_Char_Data_Char_Grade] DEFAULT (0) FOR [Char_Grade],
CONSTRAINT [DF_Char_Data_Char_Ext] DEFAULT (0) FOR [Char_Ext],
CONSTRAINT [DF_Char_Data_Char_CHK] DEFAULT (0) FOR [Char_CHK]
GO
------------------------------------------------------
결론을 말씀드리자면..트리거문에 for update 가아닌 instead of update 를 사용하면 잘작동하더라구요. 하지만 instead of update
를 사용하니 데이터값들이 증가하질않고 계속 원상복귀에요.
char_level을 예로들자면 트리거가작동해서 char_level = 11
이되고 또 업데이트이벤트가일어나면 char_level의 값이 증가하질않
는다는거죠. for update를 사용하면 저런오류가 뜨궁..휴.;;
혹시 replace 함수 때문인건가요.?
초보라 설명이 이상하네요..ㅠㅠ 해결책좀..부탁합니다.ㅠ