我有一个很大的数据库 里面有很多表
删除每个表里面的第一条记录 ID=1
该怎么写语句?

解决方案 »

  1.   

    没什么好办法,只能一个一个删除了。最多你是用脚本来得到所有的表名,然后如果表中有字段ID,则进行delete from
      

  2.   

    写个脚本,show tables from ...(你的库名),然后遍历表
      

  3.   

    用SP,取得所有表名,再用字符串累计生成SQL语句,动态执行
      

  4.   

    //先在数据库中找出 你的数据库(假设为 mytest)中所有的表select table_name from information_schema.clounms where table_schema = "mytest";如果你所有的表都有字段ID就可以查找字段为1的select ID  from(
    select table_name from information_schema.clounms where table_schema = "mytest";
    ) t where t.ID = 1;删除就是:
    delete t (select table_name from information_schema.clounms where table_schema = "mytest";
    ) AS t  where t.ID = 1;改下数据库的名字
    你可以依次试试!