另外,这样的语句,是否存在语法错误?delete table1 from table1,table where table1.id="&id&" and table1.myinfo=table2.myinfo"这个语句是否能满足table1中的id等于变量id,并且该条记录的myinfo等于table2.myinfo?

解决方案 »

  1.   

    自己可以建个测试库做测试了,这样比较安全。一次删除多表不一定行的通吧,delete from后面一般只跟一个表的。DELETE table1 FROM table1,table2 WHERE table1.id=table2.id;这种语句应该是不合语法的。要和其他表关联的话可以:DELETE FROM table1 WHERE table1.id=table2.id;这个mysql也不一定支持,我试过低版本的不行,postgresql是没问题的。
      

  2.   

    DELETE table1 FROM table1,table2 WHERE table1.id=table2.id;
    只删除table1的数据
    delete table1 from table1,table where table1.id="&id&" and table1.myinfo=table2.myinfo"
    这条语句没有语法错误
      

  3.   

    DELETE table1 FROM table1,table2 WHERE table1.id=table2.id;
    delete table1 from table1,table where table1.id="&id&" and table1.myinfo=table2.myinfo"
    -----------------------------------------------
    在 postgresql 上上面两条语句都有语法错误。
    delete from 和 where 之间只能有一个表。下面是 PostgreSQL 8.0 中 delete 语句的用法说明:6.3. Deleting Data
    So far we have explained how to add data to tables and how to change data. What remains is to discuss how to remove data that is no longer needed. Just as adding data is only possible in whole rows, you can only remove entire rows from a table. In the previous section we discussed that SQL does not provide a way to directly address individual rows. Therefore, removing rows can only be done by specifying conditions that the rows to be removed have to match. If you have a primary key in the table then you can specify the exact row. But you can also remove groups of rows matching a condition, or you can remove all rows in the table at once. You use the DELETE command to remove rows; the syntax is very similar to the UPDATE command. For instance, to remove all rows from the products table that have a price of 10, use DELETE FROM products WHERE price = 10;If you simply write DELETE FROM products;
    then all rows in the table will be deleted! Caveat programmer.