本文介绍了如何在插入后创建更新表的触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,假设我有一个名为 tabpeople 的表,它有以下字段: id (主键自动增量),数字(文本)和名称(文本)。如何创建始终在添加人员后的触发器,数字字段将更新为与 id 字段具有5个前导零的相同值?



谢谢大家。



我的尝试:



我试图调整一些我发现的例子,但我不能这样做。

Hello everyone, assuming I have a table called tabpeople and it has the fields: id (primary key auto increment), number (text) and name (text). How can I create a trigger that always after adding a person, the number field is updated to the same value as the id field with 5 leading zeros?

Thank you all.

What I have tried:

I tried to adapt some examples that I found but I could not do that.

推荐答案

CREATE TRIGGER tabpeople_i
   ON  tabpeople
   FOR  INSERT
AS
BEGIN
SET NOCOUNT ON;
UPDATE t
	SET name='00000'+LTRIM(rtrim(str(i.id)))
	FROM tabpeople t
	JOIN inserted I
		ON i.id=t.id

END


这篇关于如何在插入后创建更新表的触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:03