表1 type1 info1 * 1 2表2
type2 info2 *
1 2表3
type3 info3 *
1 2如何同时删除 数据为1 和 2 的三张表的 记录
一条SQL语句, 怎么用视图 写出 这样的SQL 大家是怎么学会这样方法的
type2 info2 *
1 2表3
type3 info3 *
1 2如何同时删除 数据为1 和 2 的三张表的 记录
一条SQL语句, 怎么用视图 写出 这样的SQL 大家是怎么学会这样方法的
解决方案 »
- 小白不会使用AspNetPager,请高人指教!
- randomfeel 求救
- 很棘手的问题 关于 Windows2003Serever 架设网站的问题
- 请问谁做过用ASP.NET做过GIS开发,帮忙看下mxd图片如何反键另存为其中的一个层
- FreeTextBox 中图片不显示,可我的程序功能可以实现
- C#的临时表绑定后,无法显示!(求救)
- 如何在页面上用一个按钮直接打开一个文件?
- 各位带**********星的进来看看啊,有关DATAGRID巨巨巨巨巨巨巨巨难的问题,排序,显示图片方面的,先放60,可加分
- 怎么在"网站设计领域 "(包括后台)混口饭吃?
- 将datetime转换成bigint格式如 20021001235959
- 急,出现这样的情况是啥意思,asp.net,如何解决,我该怎么么,我是初学者
- 关于<bgsound>的问题
即是要union 还是 join
不明白你这个视图将会是怎样的结构. 因为你所说的删数据,我也不知道是指删什么.
表1.type1='1' and 表1.info1='2'
表2.type2='1' and 表1.info2='2'
表3.type3='1' and 表1.info3='2'
这些记录
insert t1 select 1,2 union select 3,2 union select 2,1
create table t2(type2 int primary key check(type2 between 11 and 20), info2 int)
insert t2 select 11,1 union select 15,2 union select 12,1
create table t3(type3 int primary key check(type3 between 21 and 100), info3 int)
insert t3 select 31,1 union select 33,2 union select 23,1
go
create view t
as
select type1,info1 from t1
union all
select type2,info2 from t2
union all
select type3,info3 from t3
go
select * from t
delete from t where (type1=1 and info1=2) or (type1=1 and info1=2) or (type1=1 and info1=2)
/*
或用以下两种写法的任一种
delete from t where type1=1 and info1=2
delete a from t a inner join
(select type1=1,info1=2 union select type1=1,info1=2 union select type1=1,info1=2) b
on a.type1=b.type1 and a.info1=b.info1*/
go
select * from t
drop table t1,t2,t3
drop view t
go
如果不依赖于主健分区,那么还是要借助触发器.只不过建视图时,给每个表另个来源识别的虚列.create view t as
select *,frm=1 from t1
union
select *,frm=2 from t2
union
select *,frm=3 from t3--进行删除操作
delete from t where (type1=1 and info1=2) or (type1=1 and info1=2) or (type1=1 and info1=2) and frm in(1,2,3) --只删除t1中的,那么in中就只出现1
/*
或用以下两种写法的任一种
delete from t where type1=1 and info1=2 and frm in(1,2,3)
delete a from t a inner join
(select type1=1,info1=2,frm=1 union select type1=1,info1=2,frm=2 union select type1=1,info1=2,frm=3) b
on a.type1=b.type1 and a.info1=b.info1 and a.frm=b.frm*/--然后,给t创建 instead of delete触发器,在触发器中完成操作.
create trigger tr
on t
instead of delete
...--略去
insert t1 select 1,2 union select 3,2 union select 2,1
create table t2(type2 int primary key check(type2 between 11 and 20), info2 int)
insert t2 select 11,1 union select 15,2 union select 12,1
create table t3(type3 int primary key check(type3 between 21 and 100), info3 int)
insert t3 select 31,1 union select 33,2 union select 23,1
go
create view t
as
select type1,info1 from t1
union all
select type2,info2 from t2
union all
select type3,info3 from t3
go
select * from t
delete from t where (type1=1 and info1=2) or (type1=1 and info1=2) or (type1=1 and info1=2)
/*
或用以下两种写法的任一种
delete from t where type1=1 and info1=2
delete a from t a inner join
(select type1=1,info1=2 union select type1=1,info1=2 union select type1=1,info1=2) b
on a.type1=b.type1 and a.info1=b.info1*/
go
select * from t
drop table t1,t2,t3
drop view t
go
即是要union 还是 join
不明白你这个视图将会是怎样的结构. 因为你所说的删数据,我也不知道是指删什么.