MySQL表操作

  一 . 查看數(shù)據(jù)庫(kù)中的表格:

    -- 查看當(dāng)前數(shù)據(jù)庫(kù)中的數(shù)據(jù)表 : show tables;

    -- 查看指定數(shù)據(jù)庫(kù)中的數(shù)據(jù)表 : show tables from 數(shù)據(jù)庫(kù)名;

 

  二 ,創(chuàng)建表:

      create table [if not exists] 表名 (

      字段名  字段類型,

      ...  ...

      );

 

   三,查看表:

      1,查看表的創(chuàng)建信息:

        show create table 表名;

      2, 查看表字段信息:

        方法一  :desc 表名;      ==>desc 命名  describe

        方法二 : show columns from 表名;

 

   四, 刪除表:

      drop table 表名;

 

   五,添加字段:

      1,添加單個(gè)字段:

        alter table 表名  add 字段名  字段類型;

      

      2,添加多個(gè)字段:

        alter table 表名  add (

            字段名  字段類型 ,

            字段名  字段類型 ,

            ...  ...

            );

 

    六,修改表字段:

      1,刪除表字段:

        alter table drop 字段名;

      2,修改表字段類型:

        alter table 表名 modify 字段名  字段類型;

        3,修改表字段名:

        alter table 表名 change 原字段名 新字段名 字段類型;

        4,修改表名:

        alter table 原表名 rename 新表名;

       5,添加字段:

        ---  在表最后一列添加:

          alter table 表名 add 字段名 字段類型;

        --- 在表的第一列添加:

          alter table 表名 add 字段名  字段類型  first;

        --- 在表的指定列之后添加:

          alter table 表名  add  字段名 字段類型  after 已有字段名;