zoukankan      html  css  js  c++  java
  • 用mysql workbench进行数据相关的操作基础

    1.j建库,点击creat schema,输入名字,点击应用。

    建立成功后在表格里可以看到创建后的数据库了,可以点击table创建表

    2.如果要求建立如下表时。

     首先构建好表的结构

     右键mysql workbench里数据库下面表,创建新表

    - PK: primary key (column is part of a pk)  主键
    - NN: not null (column is nullable) 是否为空
    - UQ: unique (column is part of a unique key) 外键
    - AI: auto increment (the column is auto incremented when rows are inserted) 自动增加
    - BIN: binary (if dt is a blob or similar, this indicates that is binary data, rather than text) 二进制
    - UN: unsigned (for integer types, see docs: “10.2. Numeric Types”)
    - ZF: zero fill (rather a display related flag, see docs: “10.2. Numeric Types”)

     3.操作表,增、删、改、查

    • insert into users(username, `password`, realname) values ('zhangsan','123','张三');
      

        password是sql里的关键字,所以要用``包裹起来。


    • select * from users;
      select id,username from users;

      select * from users where username = 'zhangsan' and 'password' = '123';
      select * from users where username = 'zhangsan' or 'password' = '123';
      select * from users where username like '%zhang%';
      select * from users where password like '%1%';
      select * from users where username like '%1%' order by id;
      select * from users where username like '%1%' order by id desc;

      select * from users where state <> '0';

        *查询所有users表的所有列。and相当于&,or相当于|,like是模糊查询,模糊查询后面的变脸用%包裹起来。 order是排列,desc是倒序。<>是不等于的意思。

    • update users set realname='李四2' where username='lisi';

      SET SQL_SAFE_UPDATES = 0;

        改一般都是加条件的,除非整一列都需要改。执行时提示我使用的是safe update mode。可以用上面最后那句代码改一下;

    • delete from users where username='lisi';
      

        删除一定要加条件,非常危险。不过实际项目需要用到这类功能一般是通过更改数据的状态之类的东西。而不是把数据删掉。

  • 相关阅读:
    JavaScript-Runoob-JS 高级教程 :JavaScript 对象
    JavaScript-Runoob-JS HTML DOM :DOM 节点列表
    JavaScript-Runoob-JS HTML DOM :集合(Collection)
    JavaScript-Runoob-JS HTML DOM :DOM 元素
    JavaScript-Runoob-JS HTML DOM :EventListenter
    JavaScript-Runoob-JS HTML DOM :事件
    JavaScript-Runoob-JS HTML DOM :改变 CSS
    discuz的css处理机制
    discuz的diy功能介绍
    php在线支付流程
  • 原文地址:https://www.cnblogs.com/niujie/p/13702895.html
Copyright © 2011-2022 走看看