Ref: http://blog.csdn.net/duming115/archive/2008/04/15/2293714.aspx The content below 2008.04.15 is only for MySQL Databases 1. the SQL statement deletes two or more associated data. In the past, only simple operations were performed on the data in the database. Generally, only the data in a table is deleted (because the association between the table and the table is poor and there is no foreign key constraint), just like this. Delete From tablea Where 1 = 1 And a. ID = 1;After the delete operation, you do not need to specify the table name until the data in the two tables are recently deleted. Table A and table B and the content in Table B are affiliated with table, that is to say, if a record in Table A is deleted, the record in Table B is also deleted, because if the record in Table B is not deleted, junk data is formed, An item in Table A is Itemid, and a column in table B is also Itemid. It is directed to Table A in the form of a foreign key. When I write it like this, an error is reported: Delete From A, B Where 1 = 1 And a. Itemid = B. Itemid And a. ID <5Prompt that the statement after where has a problem (of course the problem is not the where statement). When the table after from involves multiple, this statement will change a bit. This way Delete A, B From A A, B Where 1 = 1 And a. Itemid = B. Itemid And a. ID <5
Or Delete From A, B Using a A, B Where 1 = 1 And a. Itemid = B. Itemid And a. ID <5The table names in from do not have sequential requirements. The following is a description in <SAMs-mysql tutorial (2003). chm>: Delete Syntax: Delete [low_priority] [quick] From table_name [Where where_definition] [Order by...] [Limit rows]
Or
Delete [low_priority] [quick] table_name [. *] [, table_name [. *]...] From table-References [Where where_definition]
Or
Delete [low_priority] [quick] From table_name [. *] [, table_name [. *]...] Using table-References [Where where_definition]
The sample code is as follows: 1. delete data from a table Delete from department where name = 'asset management ';
2. delete data from two tables Delete employee, employeeskills From employee, employeeskills, Department Where employee. employeeid = employeeskills. employeeid And employee. interval mentid = Department. interval mentid And department. Name = 'finance ';
3. Delete the data in the two tables and use the using syntax. Delete from employee, employeeskills Using Employee, employeeskills, Department Where employee. employeeid = employeeskills. employeeid And employee. interval mentid = Department. interval mentid And department. Name = 'finance ';
|