--insert语句语法
--完整的语法
INSERT INTO 表名(fieldNamel,fieldName2,fieldNameN)values(valuel.Value2,valueN);
insert into t_class(id,name)values('1','1班');
insert into t_class values('103','4');
/*
主键:我们插入数据的时候就需要保证他的唯一性
Orlace中提供的序列号的方案来解决
MySQL中提供了主键自增的方案
在分布式环境下。我们可以通过分布式ID来解决
*/
create sequence 序列名称
[INCREMENT BY] --每次自增的数量
[START WITH 1] --从1开始计数
[NOMAXVALUE] --不设置最大值
[NOCYCLE] --一直累加,不循环
CACHE 10; --缓存10
drop sequence s_class;
//每次增加1 从10开始 不设置最大值 一直累加 缓存50
create sequence s_class
increment by 1
start with 10
nomaxvalue
nocycle
cache 50;
insert into t_class values(s_class.nextval,'计算机2班');
/*
update 表名 set field1=value1,....[where]
*/
update t_class set name='计算机班' where id=100;
update t_class set name='计算机班' where id in(10,15);
update t_class set name='计算机7班' where id>15 and id<20;
update t_class set name='计算机8班' where id between 20 and 25;
update t_class set name='计算机9班' where id!=25;
update t_class set name='计算机9班' where id<>25;
--删除数据
DELETE FROM 表名 [where 条件]
--删除条件为空的数据
delete from t_class where is null;
--删除全表数据
delete from t_class; --删除会做数据的缓存
truncate table t_class; --直接删除表中数据,不做缓存处理。
--多行插入
insert into t_class_copy(id.name);
select id,name from t_class;
select * from t_class_copy
--复制表
create table t_class_copy as select *from t_class where 1!=1;
--复制表 带有数据的情况
create table t_class_copy1 as select *from t_cla