zoukankan      html  css  js  c++  java
  • php批量修改表结构

     1 <?php
     2 set_time_limit(0);
     3 $con = mysql_connect("localhost", "root", "root");
     4 $dbname = "db";
     5 if ($con) {
     6   if (mysql_select_db($dbname, $con)) {
     7     $sql = "show tables like 'pre_tb_%'";
     8     $ret = mysql_query($sql);
     9     while($row = mysql_fetch_assoc($ret)){
    10       $info1[] = $row;
    11     }
    12     foreach ($info1 as $v) {
    13       $chidarr1[] = substr($v['Tables_in_multiopen (pre_tb_%)'],7);//获取标记号
    14     }
    15     foreach ($chidarr1 as $val) {
    16       $tabname = 'stat_adclick_'.$val;
    17       $sql = "alter table $tabname add column c2 int default 0 after p";
    18       mysql_query($sql);
    19       $sql = "alter table $tabname DROP PRIMARY KEY";
    20       mysql_query($sql);
    21       $sql = "alter table $tabname add primary key(c2,p)";
    22       mysql_query($sql);
    23       $sql = "alter table $tabname drop index old_index";
    24       mysql_query($sql);
    25       $sql = "create index idx_newincex on $tabname (c2,p)";
    26       mysql_query($sql);
    27     }
    28   }
    29 }
    30 mysql_close($con);
    31 ?>
  • 相关阅读:
    csu1217: 奇数个的那个数
    小试SAS 判别分析
    bfs poj2965
    STL set常用操作
    csu1002 A+B(III)
    HDOJ 1002 的几种方法
    SQL知识积累
    CSV文件格式介绍
    ASP.net Web Form 知识积累
    C# 位域[flags] 枚举
  • 原文地址:https://www.cnblogs.com/Crius/p/6894768.html
Copyright © 2011-2022 走看看