隨筆-204  評論-149  文章-0  trackbacks-0

          mysql alter命定
          關鍵字: mysql
          mysql alter 語句用法,添加、修改、刪除字段等


          //主鍵549830479

             alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
          //增加一個新列549830479

             alter table t2 add d timestamp;
          alter table infos add ex tinyint not null default '0';
          //刪除列549830479

             alter table t2 drop column c;
          //重命名列549830479

             alter table t1 change a b integer;

          //改變列的類型549830479

             alter table t1 change b b bigint not null;
          alter table infos change list list tinyint not null default '0';

          //重命名表549830479

             alter table t1 rename t2;
          加索引549830479

             mysql> alter table tablename change depno depno int(5) not null;
          mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);
          mysql> alter table tablename add index emp_name (name);
          加主關鍵字的索引549830479

          mysql> alter table tablename add primary key(id);
          加唯一限制條件的索引549830479

            mysql> alter table tablename add unique emp_name2(cardnumber);
          刪除某個索引549830479

             mysql>alter table tablename drop index emp_name;
          修改表:549830479

          增加字段:549830479

             mysql> ALTER TABLE table_name ADD field_name field_type;
          修改原字段名稱及類型:549830479

             mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
          刪除字段:549830479

             mysql> ALTER TABLE table_name DROP field_name;

           

          mysql 常用增刪改查命定
          關鍵字: mysql增刪改查
          插入一條記錄:
                    mysql> insert into table_name (column_name1,column_name2,.) values (value1,value2,..);
          更新一條記錄:
                    mysql> update tbl_name
          set col_name1=expr1 [, col_name2=expr2 ...][WHERE where_definition]
          [ORDER BY ...][LIMIT row_count];
          刪除一條記錄:
                   mysql>delete from table_name where id=XX;
          刪除整個表的數據:
                   mysql> drop from table_name;
          查詢一條記錄:
                   mysql>select * from table_name where id=XX;

           

           

          mysql中刪除部分重復記錄的方法
          關鍵字: mysql中刪除部分重復記錄
          假設person表中有三個字段 分別是id(自增) name age 部分記錄中的name ,age出現重復
          比如
          id             name              age
          1           zhangsan            20
          2           zhangsan            20
          3               lisi                    25
          4               lisi                    25
          1 ,2 部分重復,3,4也是部分重復 ,現在四條記錄我只保留不重復的兩條。刪除方法如下:

          1.按name,age分組查詢出所有不重復的id并放入到tmp表中
            create table tmp select min(id) as id from person group by name,age;

          2.根據上面查詢出的id號從person表中查詢出所有的數據并放到表tmp2中
            create table tmp2 select person.* from person,tmp where person.id = tmp.id;

          3.刪除person表
            drop table person;

          4.把tmp2重命名為person
            rename table tmp2 to person;

           


           

          posted on 2009-07-25 00:24 Frank_Fang 閱讀(358) 評論(0)  編輯  收藏 所屬分類: SSH+JQuery+DWR
          主站蜘蛛池模板: 洛浦县| 东宁县| 福鼎市| 池州市| 英山县| 达州市| 呼玛县| 从江县| 铅山县| 西林县| 定襄县| 平原县| 望城县| 富平县| 哈尔滨市| 清水县| 吉隆县| 南开区| 淳化县| 丰宁| 若羌县| 扎囊县| 建阳市| 慈溪市| 桐城市| 长岛县| 贵溪市| 赞皇县| 万州区| 建瓯市| 尖扎县| 潮安县| 和龙市| 永寿县| 江西省| 石阡县| 临沧市| 东乡| 镶黄旗| 金华市| 静宁县|