数据库的增删改查
增
create database z_1031 charset utf8;
/*utf8作为编码,必须有*/
删
drop database z_1031;
改
alter database;
查
show databases;
当我们建好库之后若想进入库则通过 use 库名;来进入所选的库
表的增删改查
增 create table 表名;
基本形式如下
create table [if not exists] 表名(
字段列表, [约束或索引列表],
字段列表, [约束或索引列表],
索引
约束
) [表选项列表];
来个实栗:
create table student(
sno varchar(20) not null primary key comment '学号',
sname varchar(20) not null comment '学生姓名',
ssex varchar(20) not null comment '学生性别',
sbirthday Datetime comment '学生出生年月',
class varchar(20) comment '学生所在班级'
);
删 drop table 表名;
修改表名 alter table 旧表名 rename to 新表名;
修改表的字段 alter table 表名 change 原字段名 新字段名 新字段类型 新字段属性;
查看所有表 show tables;
查看表结构 desc 表名;