sqlserver 触发器问题
我想做一个触发器,但修改表T的字段C1时,判断如果修改后的值为-1,则更新表T该行记录的字段C2为某值。
CreateTRIGGER [Tri_UpdateLastSaveDate] ON [dbo].[T]
for UPDATE
AS
BEGIN
if update(C1)
begin
if inserted.C1='-1'
begin
update T set C2=convert(varchar,getdate(),21)
where C3=(select C3 from inserted);
end
end
END
可是执行的时候总是报错:
No row was updated.
Error Source:Microsoft.VisualStudio.DataTools.
Error Message: The row value(s) updated or deleted either do not make the row unique or they alter multiple rows(2 rows)
表T没有主键,且C3字段实际是唯一值
我把update这句话去掉,新建了一个表AA,包含字段c1、c2,也没有主键。
替换成update AA set AA.C1='99' from AA,Inserted
where AA.C1=Inserted.C1
可是还是提示这样的错误。
请帮忙解决,着急。谢谢。
SQL code:
CreateTRIGGER [Tri_UpdateLastSaveDate] ON [dbo].[T]
for UPDATE
AS
BEGIN
if update(C1)
begin
update T set C2=convert(varchar,getdate(),21)
from T,inserted i
where T.C3=i.C3
and i.C1='-1';
end
END
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware
相关问答:
我在学习使用SQL Server Compact Edition创建移动应用程序,可是在数据库创建发布第一步时提示错误如下:
There are no publications to which you subscribe,either because this server has no publicati ......
能否用语句实现。而不是现成的工具?
楼上的兄弟可以详细一些吗?
祝你节日快乐!哈哈
节日快乐
SQL code:
一. 导出工具 exp
1. 它是操作系统下一个可执行的文件 存放目录/ORACLE_HOME/bin
......
比如 用户名,我程序的要求是10位字符以内,所以:
如果我sqlserver从varchar(50)存储改为用varchar(10)的话,
1.会不会减少数据空间?
2.会不会提高我程序的效率?
3.有没有必要?
小弟先谢 ......
SQL code:
CREATE TABLE TUser
(
FName CHAR(8000),
FAge INT,
FSex bit
)
INSERT INTO TUser
SELECT '张三',18,1
UNION ALL
SELECT '李四',20,1
UNION ALL
SELECT '王五',32,1
UNION ALL
SE ......