SQL Server 2008 中的简单触发器

发布于 2024-09-25 21:04:45 字数 145 浏览 0 评论 0原文

谁能告诉我当记录插入数据库时​​如何更新记录的列。 这是我想要的伪代码。

if( mytable.OriginalId == null )
    mytable.OriginalId = Scope_Identity();

Can anybody tell me how can I update a column of a record when it is inserted to the database.
Here's the pseudocode that I want.

if( mytable.OriginalId == null )
    mytable.OriginalId = Scope_Identity();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱&纷飞 2024-10-02 21:04:45

我认为这会是矛盾的。 OriginalId 要么已设置,要么未在插入时设置。

如果不是,Scope_Identity() 从哪里获取它的值?如果它来自另一列,那么使用计算列不是更好吗?

抱歉,目前尚不清楚总体目标是什么...您通常不会使用触发器,特别是如果 OriginalId 是 PK 的一部分

This would be contradictory I think. Either OriginalId is set or it isn't on insert.

If it isn't where does Scope_Identity() get it's value from? If it's from another column then would it not be better to use a computed column?

Sorry, it's not clear what the overall objective is... you would not normally use a trigger especially if OriginalId is part of the PK

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文