MySql数据库-03DDL语言(下)之操作数据表

大家看完了操作数据,那么我们就来看看操作数据

   1,创建表:

       create table 表名( 字段1 字段类型,字段2 字段类型,...字段n 字段类型);
                           例:crate table user(_id int ,name text,pw char(10),sex varchar(1));

  2,修改表:

                           1,表名改为aa。
                                 rename table 原表名   to  要修改成表名;
                                   :rename table user to aa;

                           2,在已有表的基本上增加一个like列。
                                 alter table 表名   add 字段名 字段类型;
                                 : alter table user add like text;

                           3,列名name修改为username。
                                alter table 表名 change 原字段名  新字段名  字段类型;(注意:字段类型可修改也可不修改,但必须添加)
                                :alter table user change name username text;   

                          4,修改like列,使其长度为50,(或者字段数据类型)
                                 alter table 表名  modify 字段名 varchar(50);  alter table 表名 modify 字段名 字段类型;
                                 :alter table user modify like varchar(50);
                                          alter table user modify like text;

            

  3,查询表:

                         1,查询数据库中所有表
                                show tables;

                         2,查看表格的创建细节
                               show create table 表名;
                               :show create table user;

  4,删除表:

                            drop table 表名;
                              :drop table user;

猜你喜欢

转载自blog.csdn.net/itszt888/article/details/78309650