22,210
社区成员
发帖
与我相关
我的任务
分享
create table 员工信息表(id int,姓名 nvarchar(10),性别 nvarchar(1))
create table 员工工资表(id int,姓名 nvarchar(10),性别 nvarchar(1),工资 int)--不管其他列
insert into 员工信息表 select 1,'张三','男'
insert into 员工工资表 select 1,'张三','男',3000
go
create trigger setygxb
on 员工信息表
for update
as
update a set 性别=b.性别 from 员工工资表 a inner join inserted b on a.id=b.id
go
update 员工信息表 set 性别='女' where 姓名='张三'
select * from 员工工资表
/*
id 姓名 性别 工资
----------- ---------- ---- -----------
1 张三 女 3000
(1 行受影响)
*/
go
drop table 员工工资表,员工信息表
如果有外键 还可以使用级联删除 这个直接去查查
一般是可以使用触发器
create trigger my_tri on 员工信息表
for update
as
update a set 性别=b.性别 from 员工工资表 a inner join inserted b on a.id=b.id
go
update 员工信息表 set 性别='女' where 姓名='张三'