前面写的那个多表查询,JDBC,字符集,本质都是数据库的分支功能应用,而主干的增删改查,才是关键,今天面试了一家公司的软件实施岗,一些基本的增删改查语句,突然就忘记怎么写了,还是应用的不够熟练
一 insert
二 delete
三 update
四 select
五 综合演示
-- 建立一个数据表
create table employee(
id int,
name1 varchar(40),
sex varchar(4),
birthday date,
entry_date date,
salary decimal(8,2),
resum text
);
drop table employee;
-- 插入数据
INSERT INTO employee(id,name1,sex,birthday,entry_date,,salary,resum)
VALUES(1,'zhangsan','male','1993-03-04','2016-11-10','1000','i am a developer');
-- 给某一列插入数据
INSERT INTO employee(id) VALUES (6);
SELECT * FROM employee;
-- 删除数据
DELETE from employee where job='zhangsan';
SELECT * from employee;
-- 删除所有数据,保存表结构
DELETE FROM employee;
-- 改数据,有东西才能改,没有东西改不成
INSERT INTO employee(id,name1,sex,birthday,entry_date,salary,resum)
values (1,'zhangsan','male','1993-03-04','2016-11-10','1000','i am a developer');
INSERT INTO employee(id,name1,sex,birthday,entry_date,salary,resum)
values (1,'aaa','male','1993-03-04','2016-11-10','1000','i am a developer');
-- 将所有员工工资修改为5000元
UPDATE employee SET salary=5000;
-- 将张三员工工资设置为600
UPDATE employee SET salary=3000 where name1='张三';
-- 将aaa员工的薪水修改为4000元,id修改为2
UPDATE employee SET salary=4000,id=2 where name1='aaa'
-- 修改是可以做加减法的
UPDATE employee SET salary=salary+6000 WHERE name1='aaa';
六 增删列的方法
alter table employee add image blob;
alter table employee modify job varchar(60);
alter table employee drop sex;
alter table user character set utf8;