oracle和mysql多表删除数据的方法一大把,好多都是没通过证明的,你极可能已经被错误信息误导了,下面我以mysql两张表删除数据为例,来让给为注意到这一点,我在mysql中新建了两张表,分别是用户表和国家表,以下所示。html
用户表users:mysql
国家表country,如图:web
当你看到这两张mysql表的时候,你必定认为多表数据删除的语句是这样的,其实这样是错误的!,以下。sql
delete from users u,country c where u.id = c.userId and u.id = 20
mysql多表删除用上面的语句会报sql syntax语法错误的,报错以下。数据库
[SQL]安全
delete from users u,country c where u.id = c.userId and u.id = 20oracle
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'u,country c where u.id = c.userId and u.id = 20' at line 1spa
mysql多表删除数据正确的方法应该使用内链接来删除,以下两条语句,可任选一句。code
//语句一 delete u,c from users u INNER JOIN country c on u.id = c.userId and u.id = 20 //语句二 delete u,c from users u INNER JOIN country c where u.id = c.userId and u.id = 10
这个时候你必定会认为,oracle删除多表数据可否用上面这两条语句?答案是:不行!,它会报以下错误。orm
“ORA-00933:SQL命令未正确使用”
说明oracle使用上面的两条语句多表删除数据是不行的,那oracle多表删除数据该怎么写呢?命令以下。
//oracle中只能分开执行 delete from users where users.id = 20 delete from country where country.userId = 20
在oracle中不能进行多表关联删除,这可能跟oracle数据库的安全机制有关,你只能把上面的语句分红两条sql语句来执行才能够实现oracle的多表删除。