数据表
创建
create table 数据表的名字(字段 类型 约束[,字段 类型 约束]);
- unsigned无符号 整形
- auto_increment 自动增长
- primary key 主键 唯一标识这条数据
- not null 不能为空
create table student(
id int unsigned auto_increment primary key not null,
name varchar(30) not null,
age tinyint unsigned default 0,
weight decimal(4,2),
gender enum("男","女","保密","中") default "保密"
);
查看数据库字段
- desc student
修改字段
alter table 表名 add 列名 类型;
添加birthday
alter table student add birthday datetime;
change修改字段 (可以给字段改名字)
alter table 表名 change 原名 新名 类型及约束;
birthday改为birth 添加约束not null
alter table students change b