CREATE TABLE Post
(
postID - PK
memberID
title
thread
.
.
.
reported int DEFAULT 0,
dateCreated datetime DEFAULT GetDate() NOT NULL
);
我想编写一个存储过程,每次执行该过程时会将“报告”字段提高1。有什么想法吗?
答案 0 :(得分:4)
怎么样:
CREATE PROCEDURE dbo.UpdateReported(@PostID INT)
AS BEGIN
UPDATE dbo.Post
SET Reported = Reported + 1
WHERE PostID = @PostID
END
然后,您可以使用:
调用该存储过程EXEC dbo.UpdateReported @PostID = 5
或传递您想要更新的PostID
...
答案 1 :(得分:0)
UPDATE Post SET reported = (reported + 1)