***************************************
2月15 及联 触发器 对XML的操作 游标触发器的使用
****************************************
多表操作的关系处理
1 通过程序执行SQL
2 利用SQL2005关系及联
将删除操作设置为层叠
3 表的触发器
一般在表的操作以后触发
触发器本身是一个存储过程
触发器(trigger)是个特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由个事件来触发,比如当对一个表进行操作( insert,delete, update)时就会激活它执行。触发器经常用于加强数据的完整性约束和业务规则等。 触发器可以从 DBA_TRIGGERS ,USER_TRIGGERS 数据字典中查到。
2.当操作多条记录时(及联删除或更新)
create trigger del_id on tablename for delete
as
delete from tablename where id in(select id from deleted)
3 通过存储过程
多条插入,多条删除
<root>
<id>001</id>
<id>002</id>
</root>
--------------------------------------------------------------------------------------------------
SQL 2005作为XML格式输出
SELECT AccountID "@AccountID", AccountNums, AccountClassID, AccountDescription
FROM Account for xml path('Account'),root('Accounts')
执行结果:
<Accounts>
<Account AccountID="20081101154807"gt;
<AccountNums>-1.00</AccountNums>
<AccountClassID>61</AccountClassID>
<AccountDescription>1</AccountDescription>
</Account>
<Account AccountID="20081101180642"gt;
<AccountNums>-800.00</AccountNums>
<AccountClassID>60</AccountClassID>
<AccountDescription>kkj</AccountDescription>
</Account>
<Account AccountID="20081102164720"gt;
<AccountNums>-11.00</AccountNums>
<AccountClassID>60</AccountClassID>
<AccountDescription>11</AccountDescription>
</Account>
<Account AccountID="20081103180108"gt;
<AccountNums>-20.00</AccountNums>
<AccountClassID>61</AccountClassID>
<AccountDescription>fa</AccountDescription>
</Account>
</Accounts>
--------------------------------------------------------------------------------------------------
系统存储过程,系统函数
<Accounts>
<Account AccountID="20081101154808"gt;
<AccountNums>-1.00</AccountNums>
<AccountClassID>61</AccountClassID>
<AccountDescription>1</AccountDescription>
</Account>
<Accounts>
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[pro_insert_Account]
(@xmlAcccountList xml)
AS
BEGIN
DECLARE @iDoc int
EXEC sp_xml_preparedocument @iDoc OUTPUT, @xmlAcccountList
DECLARE @AccountID nvarchar(15)
DECLARE @AccountNums decimal(18, 2)
DECLARE @AccountClassID int
DECLARE @AccountDescription varchar(100)
DECLARE @AccountDate nvarchar(15)
DECLARE cur cursor FOR
--SELECT * FROM OPENXML (@idoc, 'Accounts/Account',1) WITH Account
SELECT * FROM OPENXML (@idoc, 'Accounts/Account',1)
WITH (AccountID nvarchar(15),AccountNums decimal(18, 2),AccountClassID int,AccountDescription varchar(100))
OPEN cur
FETCH NEXT FROM cur INTO @AccountID,@AccountNums,@AccountClassID,@AccountDescription
WHILE @@FETCH_STATUS = 0
BEGIN TRY
Insert into Account (AccountID,AccountNums,AccountClassID,AccountDescription,AccountDate) values (@AccountID,@AccountNums,@AccountClassID,@AccountDescription,GETDATE())
FETCH NEXT FROM cur INTO @AccountID,@AccountNums,@AccountClassID,@AccountDescription
END Try
BEGIN CATCH
RETURN 1000
END CATCH
EXEC sp_xml_removedocument @iDoc
CLOSE cur
DEALLOCATE cur
RETURN 0
END
--------------------------------------------------------------------------------------------------
Vss2005:源码管理器类似于java 中的CVS
浙公网安备 33010602011771号