zoukankan      html  css  js  c++  java
  • 02、数据表的操作

    数据表的操作

    -- 查看当前数据库中所有表
    show tables;
    
    -- 创建表
    -- int unsigned 无符号整形
    -- auto_increment 表示自动增长
    -- not null 表示不能为空
    -- primary key 表示主键
    -- default 默认值
    -- create table 数据表名字 (字段 类型 约束[, 字段 类型 约束]);
    create table yyy (
    	id int unsigned not null auto_increment primary key,
    	name varchar(20) not null
    );
    
    
    
    -- 创建 classes 表(id、name)
    create table classes (
    	id int unsigned not null auto_increment primary key,
    	name varchar(20) not null
    );
    
    -- 创建 students 表(id、name、age、high (decimal)、gender (enum)、cls_id)
    create table students (
    	id int unsigned not null auto_increment primary key,
    	name varchar(20) not null,
    	age int unsigned not null,
    	high decimal(5,2),
    	gender enum("男","女","保密") default "保密",
    	cls_id int unsigned
    );
    
    
    -- 查看表的创建语句
    -- show create table 表名字;
    
    show create table yyy;
    
    -- 修改表-添加字段 mascot (吉祥物)
    -- alter table 表名 add 列名 类型;
    alter table yyy add jixiangwu varchar(20);
    0
    
    -- 修改表-修改字段:不重命名版
    -- alter table 表名 modify 列名 新类型及约束;
    alter table yyy modify jixiangwu varchar(30);
    
    -- 修改表-修改字段:重命名版
    -- alter table 表名 change 原名 新名 类型及约束;
    alter table yyy change jixiangwu mascot varchar(20);
    
    -- 修改表-删除字段
    -- alter table 表名 drop 列名;
    alter table yyy drop mascot;	
    
    -- 删除表
    -- drop table 表名;
    -- drop database 数据库;
  • 相关阅读:
    Python中循环引用(import)失败的解决方法
    junit中线程需要注意的问题
    python动态绑定属性和方法
    python输出缓冲区的问题
    使用RateLimiter完成简单的大流量限流,抢购秒杀限流
    guava的限流工具RateLimiter使用
    高性能分布式锁-redisson的使用
    正则表达式
    input 标签鼠标放入输入框补全提示
    Google guava工具类的介绍和使用
  • 原文地址:https://www.cnblogs.com/zhangyu-zhj/p/12737742.html
Copyright © 2011-2022 走看看