mysql 2
mysql 2
创建表时插入主键 primary key 以下为例:
create table user(
id int primary key,
name varchar(20),
age int
);

replace插入时有相同的会进行覆盖
replace into useer values (1,liulele,22);

设置字段不能为空
alter table user add address varchar(20) not null;

默认为 defauit
alter table user add sex varchar(20) not null defauit "boy";


递增 auto_increment
创建表时需添加 以下为例:
create table user(
id int primary key aotu_increment,
name varchar(20)
);



唯一性约束 UNIQUE
alter table user add code varchar(18) UNIQUE;

修改表里的内容
update user set age=18 where id=1;

删除数据
删除一列
delete from user where id=1;

删除全部
delete from user;

快速删除表里数以万计的数据
truncate table user;

克隆表(只能克隆到表的结构,不能克隆表中的数据)
create table info like user;

把一个表的数据批量导入另一个表中
insert into user select * from info;
mysql查询 select
查看全部字段
select * from user;

按字段查询
select bane from user;

查询表中有多少行数据
select count(*) from user;

快速查询表中有多少行数据
select count(1) user;

条件过滤
and同时满足两个条件
or 满足两个条件

in 包含

不包含 not in

范围 between and

不在这个范围内 not between and

正则查询
%任意字符串

^开头

$结尾

导入本地数据
先进到存储数据的目录下
输入命令: mysql -hlocalhost -uroot -p <employees.sql


浙公网安备 33010602011771号