MySQL-数据表语句

-- 查看当前数据库中所有表
    show tables;
    
 
-- 创建表
    -- int unsigned 无符号整形
    -- auto_increment 表示自动增长
    -- not null 表示不能为空
    -- primary key 表示主键
    -- default 默认值
    -- create table 数据表名字 (字段 类型 约束[, 字段 类型 约束]);
 
    字段可以没有约束 必须有数据类型(注意!!!!)
    数据类型必须放在最前面,数据约束之间位置可以互换
    create table laoxie(
        id int unsigned primary key auto_increment not null,
        name varchar(20)
    );
 
-- 查看表结构
    -- desc 数据表的名字;
    desc laoxie;
 
-- 查看表的创建语句
    -- show create table 表名字;
    show create table laoxie;
 
    -- 修改表-添加字段 mascot (吉祥物)
    -- alter table 表名 add 列名 类型;
    alter table classes add jixiangwu varchar(20);
 
    -- 修改表-修改字段:不重命名版
    -- alter table 表名 modify 列名 类型及约束;
    alter table classes modify jixiangwu varchar(30);
 
 
    -- 修改表-修改字段:重命名版
    -- alter table 表名 change 原名 新名 类型及约束;
    alter table classes change jixiangwu mascot varchar(20);
 
 
    -- 修改表-删除字段
    -- alter table 表名 drop 列名;
    alter table classes drop mascot;
 
-- 删除表
    -- drop table 表名;
    -- drop database 数据库;
 

猜你喜欢

转载自www.cnblogs.com/lab-zj/p/12166499.html
今日推荐