try: ---------------------------------------------------------------------- create trigger trg_B on B instead of insert as begin insert into B select b.parent_id,A.[text] from A,inserted b where A.ID=b.parent_id end go
create trigger trigger_b on B for insert as begin update B set parent_text=a.[text] from a,inserted b where a.id=b.parent_id end
Create Trigger Insert_A On B Instead Of Insert As Insert B Select T1.parent_id,T2.[text] From Inserted T1 Inner Join A T2 On T1.parent_id=T2.id GO
CREATE TRIGGER T_b ON B表 instead of update for begin update B表 set parent_text=a.text from updated a inner join A表 b on a.parent_id=b.id end
paoluo(一天到晚游泳的鱼)说的有道理:create trigger trigger_b on B for insert as begin update B set parent_text=a.[text] from a,inserted t where a.id=t.parent_id end
CREATE TRIGGER Tr_b ON B instead of insert for begin update B set parent_text=a.text from inserted t1 inner join A t2 on t1.parent_id=t2.id end
出来了一个很严重的问题啊 select top 5 parent_text,count(parent_text) as textCount from userFav where parent_text!='根目录' group by parent_text order by textCount desc 这样写在查询分析器里面执行的结果是不包含根目录的 但是写在c#里面怎么结果老是包含了根目录 郁闷啊 下午4。30准时结帐 谢谢大家
怎麼可能會更新所有的列??我用的是Instead Of Insert。
--建立測試環境 Create Table A (id Int, [text] Varchar(10))Create Table B (parent_id Int, parent_text Varchar(10)) GO --插入數據 Insert A Select 1,'aa' Union All Select 2,'bb' Union All Select 3,'cc' Union All Select 4,'dd' Union All Select 5,'ee' GO --建立觸發器 Create Trigger Insert_A On B Instead Of Insert As Insert B Select T1.parent_id,T2.[text] From Inserted T1 Inner Join A T2 On T1.parent_id=T2.id GO --測試 --一次只插入一條 Insert B(parent_id) Select 1--批量插入 Insert B(parent_id) Select 2 Union All Select 3 --一次只插入一條 Insert B(parent_id) Select 5 Select * From B GO --刪除測試環境 Drop Table A,B --結果 /* parent_id parent_id 1 aa 2 bb 3 cc 5 ee */
Create Trigger Insert_userFav On userFav Instead Of Insert As Insert userFav Select A.parent_id,B.this_title From Inserted A Inner Join userFolderFav B On A.parent_id=B.this_id GO
现在我这样写正确了,谢谢大家! CREATE TRIGGER [my_trig] ON [dbo].[userFav] FOR INSERT AS update userFav set parent_text=t2.this_title from inserted t1, userFolderFav t2,userFav where t1.parent_id=t2.this_id and t1.this_id=userFav.this_id但是怎么 select top 5 parent_text,count(parent_text) as textCount from userFav where parent_text!='根目录' group by parent_text order by textCount desc 这样写在查询分析器里面执行的结果是不包含根目录的 但是写在c#里面怎么结果老是包含了根目录 郁闷啊 下午4。30准时结帐
C#代碼看看。或者select top 5 parent_text,count(parent_text) as textCount from userFav where parent_text!=N'根目录' group by parent_text order by textCount desc 加個N試試
----------------------------------------------------------------------
create trigger trg_B on B
instead of insert
as
begin
insert into B select b.parent_id,A.[text] from A,inserted b where A.ID=b.parent_id
end
go
on B
for insert
as
begin
update B set parent_text=a.[text] from a,inserted b where a.id=b.parent_id
end
On B
Instead Of Insert
As
Insert B Select T1.parent_id,T2.[text] From Inserted T1 Inner Join A T2 On T1.parent_id=T2.id
GO
instead of update
for
begin
update B表
set parent_text=a.text
from updated a inner join A表 b
on a.parent_id=b.id
end
on B
for insert
as
begin
update B set parent_text=a.[text] from a,inserted t where a.id=t.parent_id
end
instead of insert
for
begin
update B set parent_text=a.text
from inserted t1 inner join A t2 on t1.parent_id=t2.id
end
select top 5 parent_text,count(parent_text) as textCount from userFav where parent_text!='根目录' group by parent_text order by textCount desc
这样写在查询分析器里面执行的结果是不包含根目录的
但是写在c#里面怎么结果老是包含了根目录
郁闷啊
下午4。30准时结帐
谢谢大家
Create Table A
(id Int,
[text] Varchar(10))Create Table B
(parent_id Int,
parent_text Varchar(10))
GO
--插入數據
Insert A Select 1,'aa'
Union All Select 2,'bb'
Union All Select 3,'cc'
Union All Select 4,'dd'
Union All Select 5,'ee'
GO
--建立觸發器
Create Trigger Insert_A
On B
Instead Of Insert
As
Insert B Select T1.parent_id,T2.[text] From Inserted T1 Inner Join A T2 On T1.parent_id=T2.id
GO
--測試
--一次只插入一條
Insert B(parent_id) Select 1--批量插入
Insert B(parent_id) Select 2
Union All Select 3
--一次只插入一條
Insert B(parent_id) Select 5
Select * From B
GO
--刪除測試環境
Drop Table A,B
--結果
/*
parent_id parent_id
1 aa
2 bb
3 cc
5 ee
*/
表userFolderFav 列this_id,this_title
当插入userFav表的parent_id列的时候触发:用这个parent_id去找表userFolderFav表的this_id
列
然后取出this_title,再更新userFav的parent_text列为取出的this_title
就是这样的
怎么一直都不正确呢?
On userFav
Instead Of Insert
As
Insert userFav Select A.parent_id,B.this_title From Inserted A Inner Join userFolderFav B On A.parent_id=B.this_id
GO
CREATE TRIGGER [my_trig] ON [dbo].[userFav]
FOR INSERT
AS
update userFav set parent_text=t2.this_title from inserted t1, userFolderFav t2,userFav where t1.parent_id=t2.this_id and t1.this_id=userFav.this_id但是怎么
select top 5 parent_text,count(parent_text) as textCount from userFav where parent_text!='根目录' group by parent_text order by textCount desc
这样写在查询分析器里面执行的结果是不包含根目录的
但是写在c#里面怎么结果老是包含了根目录
郁闷啊
下午4。30准时结帐
加個N試試