mysql

作者: WANGLIN_HZ | 来源:发表于2018-08-08 20:14 被阅读0次

    增(insert into)

    首先创建一个表

    CREATE TABLE customers ( userid int NOT NULL AUTO_INCREMENT, name char(50) NOT NULL, address char(200) NOT NULL, email char(50) NOT NULL, PRIMARY KEY(userid) );

    插入完整行

    INSERT INTO customers values(10010,'小小','北京市朝阳区','1234567@qq.com')

    查询已插入的数据

    SELECT * FROM customers;

    根据列插入数据

    INSERT INTO customers(userid,name,adress,email) values('10077','张三','北京市通州区','1234789@qq.com')

    多行插入

    INSERT INTO customers(userid,name,adress,email) values ('10011','王五','北京市通州区','1234789@qq.com'), ('10012','王五','北京市通州区','1234789@qq.com'), ('10013','王五','北京市通州区','1234789@qq.com');

    将一个表里的数据插入到另一个表中

    insert into 表 (列名,列名...) select 列名,列名... from 表

    删除数据

    DELETE FROM customers WHERE userid = 10010;

    • 从表中删除所有行
      delete from 表

    UPDATE customers SET email='123@sina.com' where userid=10011;

    检测单个列

    SELECT 列名 FROM 表名;

    检测多个列

    SELECT 列名,列名,列名,列名,... FROM 表名;

    检测所有列

    SELECT * FROM 表名;


    =等于

    select name from customers where name='王五';

    <>不等于

    select name from customers where name<>'王五';

    !=不等于

    select name from customers where name!='王五';

    <小于

    select name from customers where name<'王五';
    select * from customers where userid<10013;

    <=小于等于

    select * from customers where userid<=10013;

    >大于

    select * from customers where userid>10013;

    >=大于等于

    select * from customers where userid>=10014;


    通配符

    %表示任何字符出现任意次数

    SELECT name FROM students WHERE name like “王%”

    通配符可在搜索模式中任意位置使用,并且可以使用多个通配符

    SELECT name FROM customers WHERE name LIKE '%子%';

    另一个有用的通配符是下划线( )。下划线的用途与%一样,但下划线只匹配单个字符而不是多个字符
    SELECT name FROM customers WHERE name LIKE "李%"; SELECT name FROM customers WHERE name LIKE "王
    ";

    相关文章

      网友评论

          本文标题:mysql

          本文链接:https://www.haomeiwen.com/subject/hnaxbftx.html