CREATE TRIGGER [upd] ON [dbo].[a] FOR insert as insert b(trendindex,unitid,begintime,trendvalue) select c.trendindex,a.unitid,a.dtime,a.tagvalue from inserted a ,c where a.unitid=c.unitid and a.dno=c.dno 行不行?
REATE TRIGGER [upd] ON [dbo].[a] FOR insert as update b set b.trendvalue=i.tagvalue from inserted i ,c where i.unitid=c.unitid and i.dno=c.dno and b.begintime= i.dtime and b.trendindex=c.trendindex and b.unitid=c.unitidinsert b(trendindex,unitid,begintime,trendvalue) select c.trendindex,a.unitid,a.dtime,a.tagvalue from inserted i ,c where i.unitid=c.unitid and i.dno=c.dno and not exists ( select * from b where and b.begintime= i.dtime and b.trendindex=c.trendindex and b.unitid=c.unitid ) go
yang: 我按你的方法,加了一个update,就通过了。 CREATE TRIGGER [upd] ON [dbo].[a] FOR insert,update as update b set b.trendvalue=i.tagvalue from inserted i ,c where i.unitid=c.unitid and i.dno=c.dno and b.begintime= i.dtime and b.trendindex=c.trendindex and b.unitid=c.unitidinsert b(trendindex,unitid,begintime,trendvalue) select c.trendindex,a.unitid,a.dtime,a.tagvalue from inserted i ,c where i.unitid=c.unitid and i.dno=c.dno and not exists ( select * from b where b.begintime= i.dtime and b.trendindex=c.trendindex and b.unitid=c.unitid ) go 现在我还剩一个问题:时间触发问题,比如:每隔10天,删掉C表中的所有内容。我看在别的贴里你告诉别人说用JOB,我也按着上面的方法做了,但是没有起任何作用。(我手头上的书里没有明确的关于JOB方面的资料,所以还的请教你了!) 我的步骤: Enterprise Manger/Tools/Job scheduling../下一步/Transact—SQL command/下一步/从Database name中选出数据库名/在Transact—SQL statement中加上如下语句:delete from b/下一步/on a recurring basic/选schedule/在occurs总选days/在右侧选天数(我做的测试,所以我选一天)/Daily frequency中选8:00(我想在一天中的固定时间来删除数据)/OK/下一步/下一步/完成 说是还得启动JOB, Management/SQL Server agent/job/选择新建的JOB,点鼠标右键,选start job,出现下面的对话框Error 22022:SQLServeragent is not currently runing so it cannot be notified of this action.我不知道该如何做????是什么原因???我那个地方错了???
Transact-SQL statement中加上如下语句: delete from f where datediff(d,begintime,getdate())>10 而且还可以设定定点运行删除程序。非常非常满意!!!我不知道如何给分,希望谁能告诉我一下,下面是我这50分的分配原则,如果有人告诉我,我将按如下分配: yang_(扬帆破浪):25分 wyarrant(ostrich):10分 x-zing(阿浩):10分 haiwer(....):5分
FOR insert
as
insert b(trendindex,unitid,begintime,trendvalue)
select c.trendindex,a.unitid,a.dtime,a.tagvalue
from inserted a ,c
where a.unitid=c.unitid and a.dno=c.dno
行不行?
FOR insert
as
update b
set b.trendvalue=i.tagvalue
from inserted i ,c
where i.unitid=c.unitid and i.dno=c.dno
and b.begintime= i.dtime
and b.trendindex=c.trendindex
and b.unitid=c.unitidinsert b(trendindex,unitid,begintime,trendvalue)
select c.trendindex,a.unitid,a.dtime,a.tagvalue
from inserted i ,c
where i.unitid=c.unitid and i.dno=c.dno
and not exists (
select * from b
where
and b.begintime= i.dtime
and b.trendindex=c.trendindex
and b.unitid=c.unitid
)
go
我按你的方法,加了一个update,就通过了。
CREATE TRIGGER [upd] ON [dbo].[a]
FOR insert,update
as
update b
set b.trendvalue=i.tagvalue
from inserted i ,c
where i.unitid=c.unitid and i.dno=c.dno
and b.begintime= i.dtime
and b.trendindex=c.trendindex
and b.unitid=c.unitidinsert b(trendindex,unitid,begintime,trendvalue)
select c.trendindex,a.unitid,a.dtime,a.tagvalue
from inserted i ,c
where i.unitid=c.unitid and i.dno=c.dno
and not exists (
select * from b
where b.begintime= i.dtime
and b.trendindex=c.trendindex
and b.unitid=c.unitid
)
go
现在我还剩一个问题:时间触发问题,比如:每隔10天,删掉C表中的所有内容。我看在别的贴里你告诉别人说用JOB,我也按着上面的方法做了,但是没有起任何作用。(我手头上的书里没有明确的关于JOB方面的资料,所以还的请教你了!)
我的步骤:
Enterprise Manger/Tools/Job scheduling../下一步/Transact—SQL command/下一步/从Database name中选出数据库名/在Transact—SQL statement中加上如下语句:delete from b/下一步/on a recurring basic/选schedule/在occurs总选days/在右侧选天数(我做的测试,所以我选一天)/Daily frequency中选8:00(我想在一天中的固定时间来删除数据)/OK/下一步/下一步/完成
说是还得启动JOB,
Management/SQL Server agent/job/选择新建的JOB,点鼠标右键,选start job,出现下面的对话框Error 22022:SQLServeragent is not currently runing so it cannot be notified of this action.我不知道该如何做????是什么原因???我那个地方错了???
或者在服务管理器里选择服务器对应的agent,把它启动然后再做job
SQLServerAgent,按绿色三角。
可是,老板却说要求数据保存十天,第十一天时删除前十一天的数据,就是说始终保持十天的记录,那该怎么做呢?这样还能用JOB做吗?谢谢了!!!!
它们是:
general,steps,schedules,notifications
我看哪个也不是调度。
此外,我不知道我说清楚了没有?我有1~10天的数据,到11天时,我删掉第1天的数据,保留2~11天的数据。
delete from f
where datediff(d,begintime,getdate())>10
而且还可以设定定点运行删除程序。非常非常满意!!!我不知道如何给分,希望谁能告诉我一下,下面是我这50分的分配原则,如果有人告诉我,我将按如下分配:
yang_(扬帆破浪):25分
wyarrant(ostrich):10分
x-zing(阿浩):10分
haiwer(....):5分