建表语句
(表名:sys_table_user;字段id、name、password、age、role_id、email、username)
create table sys_table_user(
id int(4) primary key auto_increment not null comment '主键id',
name varchar(200) not null comment '用户名',
password varchar(50) not null comment '密码',
age int(4) not null comment '年龄',
role_id int(4) not null comment '角色id'
);
删除表语句
drop table sys_table_user;
修改字段的属性
alter table sys_table_user modify name varchar(500) not null comment '用户名'
修改主键的自增(即为修改字段的属性)
alter table sys_table_user modify id int(3) unsigned not null;
修改字段的名称及属性
alter table sys_table_user change name username varchar(500) not null comment '用户名';
在现有数据表的基础上增加字段email
alter table sys_table_user add email varchar(32) not null comment '邮箱'
给字段添加默认值
alter table sys_table_user alter email set default 'javaxxx@163.com'
删除字段
alter table sys_table_user drop email;
删除字段的默认值
alter table sys_table_user alter email drop default;
删除表主键
alter table sys_table_user drop primary key;
增加表的主键
ALTER TABLE user add PRIMARY key(id)
alter table sys_table_user modify id int(3) primary key(id) not noll auto_increment;
查看表的信息
desc sys_table_user;
查看表的创建语句
show create table sys_table_user;
查看数据库种所有的表
show tables