mysql基础

-- 数据表的操作

    -- 查看当前数据库中所有表

show tables;

-- 创建表
    -- int unsigned 无符号整形
    -- auto_increment 表示自动增长
    -- not null 表示不能为空
    -- primary key 表示主键
    -- default 默认值
    -- create table 数据表名字 (字段 类型 约束[, 字段 类型 约束]);
    -- unique 唯一的

create table xxx(
		id int unsigned primary key not null auto_increment,
		name varchar(20) not null
	);

-- 查看表结构
    -- desc 数据表的名字;

desc xxx;

-- 创建 classes 表(id、name)

create table classes(
		id int unsigned primary key auto_increment not null,
		name varchar(20) not null
	);

 -- 创建 students 表(id、name、age、high (decimal)、gender (enum)、cls_id)

create table students(
		id int unsigned primary key auto_increment not null,
		name varchar(20) not null,
		age int unsigned,
		high decimal(5,2),
		gender enum("男性","女性","中性","保密") default "保密",
		cls_id int unsigned
	);

-- 查看表的创建语句
    -- show create table 表名字;

show create table xxx;

-- 修改表-添加字段 mascot (吉祥物)
    -- alter table 表名 add 列名 类型;

alter table classes add chongwu varchar(20) default"蛇";

-- 修改表-修改字段:不重命名版
    -- alter table 表名 modify 列名 类型及约束;

alter table classes modify mascot varchar(30) default"葫芦娃";

-- 修改表-修改字段:重命名版
    -- alter table 表名 change 原名 新名 类型及约束;

alter table classes change chongwu mascot varchar(20) default"法拉利";

-- 修改表-删除字段
    -- alter table 表名 drop 列名;

alter table classes drop mascot;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值