sql对表table操作

查询当前数据库下所有表名称:

  show tables;

查询表结构:

  desc user;

创建表:

  create table tb_user(

    id int,

    age int,

    score double(5,2),         -- 小数点后两位,5-2=3,三位数100,0~100.00

    birthday date,

    name char(10),     -- 定长,字符数超过10报错,‘张三’,10个字符空间,后8个被空格补齐,存储性能高,浪费空间,255bytes

    name varchar(10),     -- 变长,字符数超过10报错,‘张三’,  2个字符空间,          存储性能低,节约空间,65535bytes

    status tinyint      -- 学生状态,数字表示,正常/休学/毕业/...

 

  );

删除表:

  drop table tb_user;

  drop table if exists tb_user;

修改表:

  改表名:

    alter table student rename to stu;

  添加一列:

    alter table stu add address varchar(50);

  修改数据类型:

    alter table stu modify address char(50);

  修改列名和数据类型:

    alter table stu change address addr varchar(30);

  删除列:

    alter table stu drop addr;

 

posted @ 2023-02-27 19:16  大灰狼21  阅读(81)  评论(0)    收藏  举报