打开命令列界面
创建数据库: create database if not exists study;
查看当前的数据库
查看当前的数据库:show databases;
使用命令创建表
使用命令创建表: mysql> create table study
-> (id char(4) not null,
-> name varchar(100) not null,
-> primary key (id));
显示表的结构
显示表结构:mysql> desc student;
查看当前数据库的所有表
查看当前数据库的所有表:show tables;
查询命令:
查询命令:select * from student;
删除命令
删除命令:delete from studys;
修改表名
修改表名:alter table 旧表名 rename as 新表名;
如:alter table study rename as studys;
增加表的字段
增加表的字段:alter table 表名 add 字段名 列属性;
例:alter table student add sex varchar(12);
修改表的字段
修改表的字段:
例:alter table student modify sex varchar(2);//修改约束
alter table student change sex six varchar(12);//字段重命名
删除表的字段
删除表的字段:alter table student drop six;