Write your own SQL Server triggers practice--Master please skip it

Source: Internet
Author: User

Set ANSI_NULLS on
SET QUOTED_IDENTIFIER ON
Go

ALTER TRIGGER [Insertreplytoic]
on [dbo]. [Bbsreplytopic]
After insert
As
BEGIN
--set NOCOUNT on;

--Insert statements for trigger here

declare @uid int, @topicId int, @Rcontent nvarchar (max), @Rtime datetime, @ccode varchar (max)
, @uname nvarchar, @beReplyedUid int, @beReplyedUname nvarchar (), @replyTid int, @insertId int;
INSERT into bbsreplytopic values (
@uid, @topicId, @Rcontent, @Rtime, @ccode, @uname, @beReplyedUid, @beReplyedUname, @replyTid
) select @[email Protected] @identity
if (@insertId!=0)

Select @topicId =topicid from inserted
Update bbstopic set replycount=replycount+1 where [email protected]
print ' The ID you just inserted is ' +convert (varchar), @insertId) + ', Success '

END

INSERT into bbsreplytopic values (125,291, ' Test ', ' 2014/10/6 00:00:00 ', ' Chadao ', ' Zhangziyi ',, ' Zhangziyi ', 0)

Your own SQL Server trigger, when the reply post is replied, the number of replies to the Post field is added 1

Test success!

Write your own SQL Server triggers practice--Master please skip it

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.