社区
应用实例
帖子详情
sql server中怎么写联接更新?
accpedu
2006-12-28 10:24:37
sql server中怎么写联接更新?
就是同时(在一条语句中)更新多个表!
...全文
157
6
打赏
收藏
sql server中怎么写联接更新?
sql server中怎么写联接更新? 就是同时(在一条语句中)更新多个表!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
中国风
2006-12-28
打赏
举报
回复
create table a1(produce varchar(10) primary key)
insert into a1 select 'A'
insert into a1 select 'B'
insert into a1 select 'C'
insert into a1 select 'D'
insert into a1 select 'E'
create table a2(produce varchar(10) not null
foreign key references a1(produce) on delete cascade
on update cascade--建表时就这样定义(更新与删除)
,val int)
insert into a2 select 'A',1
insert into a2 select 'B',2
insert into a2 select 'C',3
insert into a2 select 'D',4
insert into a2 select 'E',5
测试更新:
update a1
set produce='A1'
where produce='A'
select * from a2
A1 1
B 2
C 3
D 4
E 5
(所影响的行数为 5 行)
测试删除:
delete from a1 where produce='a1'
select * from a2
produce val
---------- -----------
B 2
C 3
D 4
E 5
(所影响的行数为 4 行)
drop table a1,a2
中国风
2006-12-28
打赏
举报
回复
create table a1(produce varchar(10) primary key)
insert into a1 select 'A'
insert into a1 select 'B'
insert into a1 select 'C'
insert into a1 select 'D'
insert into a1 select 'E'
create table a2(produce varchar(10) not null
foreign key references a1(produce) on delete cascade--建表时就这样定义
,val int)
insert into a2 select 'A',1
insert into a2 select 'B',2
insert into a2 select 'C',3
insert into a2 select 'D',4
insert into a2 select 'E',5
--alter table a2 add constraint a2_con foreign key(produce)references a1(produce) on udpate cascade--这里为添加级联更新
delete from a1 where produce='a'
select * from a1
select * from a2
drop table a1,a2
楼主通过企业管理器设置不是更简单,只需要在表与表之间选择级联更新和删除就行了
中国风
2006-12-28
打赏
举报
回复
create table a1(produce varchar(10) primary key)
insert into a1 select 'A'
insert into a1 select 'B'
insert into a1 select 'C'
insert into a1 select 'D'
insert into a1 select 'E'
create table a2(produce varchar(10),val int)
insert into a2 select 'A',1
insert into a2 select 'B',2
insert into a2 select 'C',3
insert into a2 select 'D',4
insert into a2 select 'E',5
alter table a2 add constraint a2_con foreign key(produce)references a1(produce) on delete cascade
delete from a1 where produce='a'
select * from a1
select * from a2
drop table a1,a2
accpedu
2006-12-28
打赏
举报
回复
高手快来啊
accpedu
2006-12-28
打赏
举报
回复
不是有个联接更新的吗?有必要用触发器吗?
caixia615
2006-12-28
打赏
举报
回复
触发器
SQL
Server
更新
联接
概述
本文详细介绍了如何在
SQL
Server
中
使用Update Join
更新
数据,包括使用JOIN和LEFT JOIN
更新
单个和多个表格,以及注意事项,强调了在生产环境
中
执行
更新
操作时需谨慎。
SQL
Server
-
更新
[重复]时的内部
联接
本文探讨了在
SQL
Server
中
如何正确地使用INNER JOIN
更新
表,提供了三种不同的查询语句示例,解决了特定条件下
更新
ProductReviews表的问题。
SQL
Server
中
更新
视图
本文介绍了在
SQL
Server
中
更新
视图的规则与限制,包括基于多表
联接
、分组聚合操作以及行列子集视图的
更新
场景。通过具体实例说明了如何避免常见错误并成功执行
更新
操作。
SQL
server
中
视图的
更新
本文探讨了
SQL
Server
中
视图
更新
的限制条件,包括基于多表
联接
、包含分组聚合操作以及行列子集视图的
更新
规则,并通过实例说明了如何正确执行
更新
操作。
Sql
server
基本语句(增删改查)
本文详细介绍
SQL
的基本操作,包括数据的增删改查,模糊查询,分组查询以及多表
联接
查询,为初学者和进阶者提供实用的
SQL
语法指南。
应用实例
27,580
社区成员
68,548
社区内容
发帖
与我相关
我的任务
应用实例
MS-SQL Server 应用实例
复制链接
扫一扫
分享
社区描述
MS-SQL Server 应用实例
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章