34,593
社区成员
发帖
与我相关
我的任务
分享
--------------------SQL Server数据格式化工具-------------------
---------------------------------------------------------------
-- DESIGNER :happycell188(喜喜)
-- QQ :584738179
-- Development Tool :Microsoft Visual C++ 6.0 C Language
-- FUNCTION :CONVERT DATA TO T-SQL
---------------------------------------------------------------
-- Microsoft SQL Server 2005
-- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
---------------------------------------------------------------
---------------------------------------------------------------
use test
go
if object_id('test.dbo.A') is not null drop table A
-- 创建数据表
create table A
(
xml char(9)
)
go
--插入测试数据
insert into A select '华南重汽'
union all select '人事科'
union all select '财务科'
go
if object_id('test.dbo.B') is not null drop table B
-- 创建数据表
create table B
(
用户名 char(7),
密码 char(4),
所属单位 char(7)
)
go
--插入测试数据
insert into B select '乔依婷','***','财务科'
go
--代码实现
--创建触发器
create trigger tri_test
on A
for update
as
begin
update B set 所属单位=(select xml from inserted)
where 所属单位=(select xml from deleted)
end
go
--测试触发器
update A set xml='财务处' where xml='财务科'
--输出表数据
select * from A
select * from B
/*
xml
---------
华南重汽
人事科
财务处
用户名 密码 所属单位
---------------------------
乔依婷 *** 财务处
*/