insert into 表名(字段列表…) value(值列表…)
insert 数据库.表名 values(值列表…),(值列表)…
insert stu value(null,‘小华’,18736729448,22,‘北京’);
insert into stu value() value(null,‘小红’,18736729448,22,‘郑州’);
insert into stu(sname) values(‘小明1’),(‘小明2’),(‘小明3’),(‘小明4’);
replace,replace into 和insert基本一样
不一样的是:insert如果指定主键,唯一约束存在,insert则报错,replace则修改
– ifnull() if()
select ifnull(3,4),if(0,‘yes’,‘no’);
create table student(
sno int unsigned auto_increment,
sname varchar(30),
sphone char(11) null,
sage tinyint unsigned null,
asddr varchar(255) null,
primary key(sno),
unique key(sphone)
)
insert student value(null,‘小明’,132345543,22,‘郑州’);
insert into student value(null,‘小红’,54364346,null,‘北京’);
insert student(sname) values(‘小八’),(‘小七’),(‘李华’);
insert into student(sname,sphone) values(‘百里’,8975894032),(‘离枯’,5760995906),(‘张勇’,847699886);
replace into student(sname,sphone) value(‘马云’,847699886);
delete from student;
truncate student;
select * from student;
drop table student;
show tables;