1.查看数据库
show databases;
2.创建数据库
create database 数据库名字 default charset utf8mb4 ;
后面数据库名用nice代替
3.删除数据库
drop database if exists nice;
4.切换数据库
use nice;
首先,使用表操作,需要先选择数据库
1.创建表
create table biao
(
格式为:表名+类型+空否+注释
dno integer not null comment '编号',
dname varchar(20) not null comment '名称',
dlocation varchar(20) not null comment '所在地',
primary key (dno)
)engine=innodb comment='部门表';
2.查看所有表
show tables;
3.查看表结构
desc tb_dept;
4.删除表
drop table if exists tb_dept;
5.修改表
1)添加表头
alter table tb_dept add column dest date comment '成立日期';
2)删除表头
alter table tb_dept drop column dest;
3)更改属性
alter table tb_dept modify column dlocation varchar(50) not null;
alter table tb_dept change column dlocation dloc varchar(200) not null comment '所在地';
4)规定表值唯一
alter table tb_dept add constraint uk_dept_dname unique (dname);
功能去除
alter table tb_dept drop constraint uk_dept_dname;
5)规定表值长度
alter table tb_dept add constraint ck_dept_dloc check (char_length(dloc) >= 2);
去除功能
alter table tb_dept drop constraint ck_dept_dloc;
改表名
alter table tb_dept rename to department;
date
time
datetime
Y2K —> 千年虫问题
注意:不要表的字段中放很大的二进制数据或文本数据(给文件路径即可)