建立一個表
CREATE TABLE [dbo].[RoomMessage](
[roomID] [nchar](10) NOT NULL,
[Name] [nchar](10) NULL,
[Phone] [nchar](20) NULL,
[State] [bit] NOT NULL
) ON [PRIMARY]
GO
建立一個觸發器
create TRIGGER TRG_RoomState_Change
ON RoomMessage
AFTER update
AS
BEGIN
SET NOCOUNT ON;
update RoomMessage
set Name = null
,Phone = null
where exists(
select *
from inserted i
where i.State = 0
and i.roomID = RoomMessage.roomID
)
第一次寫 有點緊張
建立一個表
CREATE TABLE [dbo].[RoomMessage](
[roomID] [nchar](10) NOT NULL,
[Name] [nchar](10) NULL,
[Phone] [nchar](20) NULL,
[State] [bit] NOT NULL
) ON [PRIMARY]
GO
建立一個觸發器
create TRIGGER TRG_RoomState_Change
ON RoomMessage
AFTER update
AS
BEGIN
SET NOCOUNT ON;
update RoomMessage
set Name = null
,Phone = null
where exists(
select *
from inserted i
where i.State = 0
and i.roomID = RoomMessage.roomID
)
第一次寫 有點緊張