在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括使用INSERT实现数据
的插入、DELETE实现数据的删除以及UPDATE实现数据的更新。
更新数据 insert
更新数据 update
删除数据 delete
插入数据INSERT
1. 插入完整数据(顺序插入)
语法一:
INSERT INTO 表名(字段1,字段2,字段3…字段n) VALUES (值1,值2,值3…值n);
语法二:
INSERT INTO 表名 VALUES (值1,值2,值3…值n);
2. 指定字段插入数据
语法:
INSERT INTO 表名(字段2,字段3…) VALUES (值2,值3…);
3. 插入多条记录
语法:
INSERT INTO 表名 VALUES
(值1,值2,值3…值n),
(值1,值2,值3…值n),
(值1,值2,值3…值n);
4. 插入查询结果
语法:
INSERT INTO 表1(字段1,字段2,字段3…字段n)
SELECT (字段1,字段2,字段3…字段n) FROM 表2
WHERE …;
create table student7(id int,name varchar(20),sex enum('m','FROM'),age int(2));
desc student7;
insert into student7 values(1,'jack','m',20);
insert into student7(name,age) values('bob',21);
insert into student7 values(6,'jex','m',21),(7,'bob1','FROM',22);
create table student_his(id int,name varchar(20),sex enum('m','FROM'),age int(2));
insert into student_his SELECT * from student7 WHERE name = 'bob';
insert into student_his SELECT * from student7 WHERE age > 17;
更新数据update
语法:
UPDATE 表名 SET 字段1=值1,字段2=值2 WHERE CONDITION;
update student7 set id=8;
SELECT * from student7;
update student7 set id=9 WHERE name+"bob1";
SELECT * from student7;
update student7 set id=10,name="newrain" WHERE name="bob1";
SELECT * from student7;
删除数据delete
语法:
DELETE FROM 表名
WHERE CONITION;
DELETE FROM mysql.user WHERE authentication_string=’’;
delete from student7 WHERE name="jack";
delete from student7;
SELECT * from student7;
truncate 表名;
alter 尽量不要在高峰区使用否则服务器会变慢