Oracle multi-table joins delete? --turn

Methods oracle and mysql multi-table delete a lot of data, many of which were not proven, you are likely to have been misled by erroneous information, the following two tables I deleted to mysql data, for example, to give to this notice a little, I created two tables in mysql, are user table and the state table, as shown below.

User table users:

QQ screenshot 20171116215656.jpg

National Table country, as shown:

QQ screenshot 20171116215705.jpg

When you see these two mysql table, you must think multi-table data to delete such statements are, in fact, this is wrong! ,as follows.

delete from users u,country c where u.id = c.userId and u.id = 20

 

mysql multi-table delete statement reported by the above sql syntax syntax error, given as follows.

[SQL]

delete from users u,country c where u.id = c.userId and u.id = 20

[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 1

Multi mysql delete data table provided with correct way to remove the connection, the following two statements, an optionally.

//语句一
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

 

This time you'll think, oracle delete data able to use multi-table above these two statements? The answer is: No! , It will be reported as an error.

"ORA-00933: SQL command not properly use"

Description oracle use the above two statements are not multi-table delete data, and multi-table delete data that oracle how to write it? Command is as follows.

// the Oracle can only perform separate
 the Delete  from the Users the WHERE users.id =  20 
the Delete  from Country the WHERE country.userId =  20

 

In oracle can not delete the associated multi-table, which may be followed by security mechanisms related to oracle database, you can only put the above statement into two sql statements to perform can achieve multi-table delete oracle.

Transfer: http://www.tpyyes.com/a/mysql_oracle/2017/1116/383.html

Guess you like

Origin www.cnblogs.com/Mr-Simple001/p/10966562.html