数据库基本操作2

一.DML(Data Manipulation Language)

用来对数据库中表的数据记录进行更新

关键字:增删改

插入insert

删除delete

更新update

1.数据插入

insert into 表(列名1,列名2,列名3……)values(值1,值2,值3……)

注意:需要一一对应

insert into 表 values(值1,值2,值3……)

//向表中所有列插入值

2.数据修改

update 表名 set 字段名=值,字段名=值……;

update 表名 set 字段名=值,字段名=值……where 条件;

将所有学生的地址修改为重庆

update student set address='重庆';

将id为1004的学生的地址修改为北京

update student set address='北京' where id=1004;

3.数据删除

delete from 表名 where 条件;

truncate table 表名;/truncate 表名;

注意:delete与truncate原理不同,delete只删除内容,而truncate类似于drop table ,可以理解为将整个表删除,然后再创建该表;

删除sid为1004的学生数据

delete from student where id=1004;

删除表中所有数据

delete from student;

清空表数据

truncate table student;
truncate student;

二.总结 

数据库基本操作2_第1张图片

use mydb1;
CREATE TABLE IF NOT EXISTS EMPLOEE(
id int,
name varchar(20),
sex varchar(10),
salary double
);
#数据插入
insert into EMPLOEE values(1,'张三','男',2000),(2,'李四','男',3000),(3,'王五','女',4000);
#数据修改
update EMPLOEE set salary=6000;
update EMPLOEE set salary=3000 where name='张三';
update EMPLOEE set salary=salary+1000 where name='王五';
#数据删除
#delete from EMPLOEE;

你可能感兴趣的:(数据库,数据库)