关于deletefromjoin的信息
求助一条SQL语句,关于DELETE使用JOIN的
首先你必须得指明你删除哪个表中的数据
DELETE Works
FROM c_works Works JOIN c_works_attach Works_attach ON Works_attach.wid=Works.id JOIN c_works_image Works_image ON Works_image.wid=Works.id WHERE ( Works.id = 1 )
其次,sql server的话,得分开写,不能写到一起,你可以写一个tranction,例如
begin transaction;
declare @deletedIds table ( id int );
DELETE Works
output deleted.id into @deletedIds
FROM c_works Works JOIN c_works_attach
Works_attach ON Works_attach.wid=Works.id JOIN c_works_image Works_image
ON Works_image.wid=Works.id WHERE ( Works.id = 1 )
delete Works_attach
from c_works_attach as Works_attach
join @deletedIds d
on d.id = Works_attach.id;
delete Works_image
from c_works_image Works_image
join @deletedIds d
on d.id = Works_image.id;
commit transaction;
Wish it Helps
请教关于sql 中 delete from 删除以子查询中的数据的问题
我看你这几个表好像有主子表关联,所以不能直接从SS中删,删了数据库会报错,要先去子表中删了要删的记录,消除子记录之后才能删除主表。
先删Game 然后删area 然后删 server 最后才能删login中的数据
【oracle】delete语句同时删除多张表(在线等)
如果你是要删除2长表里的数据,可以分步做啊:
delete from a where a.ida=1;
delete from b where b.idb=1;
commit;
像你那种做法,是不可行的,不符合oracle的语法。oracle只允许从一张表中删除数据。你是不是想删除A表中的数据(B表不变),但要这些数据存在于B表中,可以使用:
DELETE FROM a WHERE (a.ida, a.name) IN (SELECT a.ida, a.name FROM a ,b where a.ida=b.idb);
COMMIT;
这些语句我都在oracle92中测试过,不知道你究竟需要做什么?
Oracle的delete与join如何使用
1. 用exists ?来替代 in
delete?from?A?where?exists
(select?1?from?B?b?where?A.num2?=?b.num1
where?b.num2?not?between?'10'?and?'10000');
不过你用not ?between,估计效率就不怎么好了。
2. 在 A 的num2,B的num1、num2上都 建立索引。