读书人

创造触发器之后对象名无效

发布时间: 2013-06-26 14:29:32 作者: rapoo

创建触发器之后对象名无效

create trigger upstudentid
on StudentInfo
for update
As
if update(StudentID)
begin update StudentScore Set StudentID=i.StudentID
From StudentScore ss , Deleted d ,Inserted i
Where ss.StudentID=d.StudentID
end

这一个触发器创建之后打开看触发器就提示[dbo].[upstudentid]对象名无效
创建了其他类型的触发器打开也是提示对象名无效
另外求解
插入信息到A表,,A表有Name列,触发插入姓名到B表Name列怎么写

[解决办法]
create trigger upstudentid on StudentInfo after update
As
BEGIN

if update(StudentID)
begin
update StudentScore Set StudentID=i.StudentID
From StudentScore ss , Deleted d ,Inserted i
Where ss.StudentID=d.StudentID
end

END

go

create trigger tri_ins_a on A after insert,UPDATE
As
BEGIN

if update(NAME)
begin

INSERT INTO B(NAME)
SELECT NAME FROM Inserted i

end

END

[解决办法]
如果建完触发器后,有对StudentInfo表drop掉重建,触发器也会被drop掉,需重建

关于触发器,可以参考一下海爷以前的一个帖子和博文

触发器综述
[解决办法]
if OBJECT_ID('table_Name1', 'u') is not null
drop table table_Name1
Create Table table_Name1
(
OID int identity(1, 1) primary key not null,
Name varchar(128) not null
)

if OBJECT_ID('table_Name2', 'u') is not null
drop table table_Name2
Create table table_Name2
(
OID int identity(1, 1) primary key not null,
Name1 varchar(128) not null
)

Create trigger InsertName on table_Name1
after Insert
as Insert into table_Name2(Name1) Select Name from Inserted

读书人网 >SQL Server

热点推荐