zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    9. MySQL
    python第四课
    python第三课pycharm的使用
    python第二课
    python第一课
    Python3基础-网络编程(8)
    Python3基础-异常处理(7)
    Python3基础-面向对象(6)
    Python3基础-模块和包(5)
    Python3基础-文件处理(4)
  • 原文地址:https://www.cnblogs.com/anyux/p/8119611.html
Copyright © 2011-2022 走看看