SQL入门-DML数据操作语言--insert into

1.使用严格模式

加大 -U 使用严格模式,限制update 和where语句

mysql -uroot -p -U

严格模式下删除数据需要使用索引,作为条件才能删除

mysql> delete from anyux.test;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
-- 提示 当前为严格模式,你更新表不能没有where条件并且使用索引

2.针对数据行的操作

 创建索引

alter table anyux.test add key id_idx(id);

删除数据

delete from anyux.test where id=8;

--提示此处建立的普通索引,索引关系为一对多,仅测试,生产环境大数据量下会很慢。

 3.表迁移

--一个库迁移到另一个库
rename table anyux.test to anyuxweb.test;

4. 插入内容

#创建表
use anyuxweb; create table anyuxweb.t1(id int ,name char(20)); desc anyuxweb.t1;

 insert into anyuxweb.t1 values(1,'a'),(2,'b');

#指定列插入数据

insert into anyuxweb.t1 (`name`) values("c");

 5.从其他表中导入数据

--创建相同表
create table anyuxweb.t2 like anyuxweb.t1;
--查看t2
desc anyuxweb.t2;
--从其他表中导入数据
insert into anyuxweb.t2 select * from anyuxweb.t1;
--查询数据
select * from anyuxweb.t2;
原文地址:https://www.cnblogs.com/anyux/p/8119611.html