zoukankan      html  css  js  c++  java
  • MariaDB INSERT,UPDATE,DELETE

    MariaDB INSERT,UPDATE,DELETE

    INSERT
    插入一整行

    (jlive)[crashcourse]>DESC customers;

    +--------------+-----------+------+-----+---------+----------------+

    | Field        | Type      | Null | Key | Default | Extra          |

    +--------------+-----------+------+-----+---------+----------------+

    | cust_id      | int(11)   | NO   | PRI | NULL    | auto_increment |

    | cust_name    | char(50)  | NO   |     | NULL                  |

    | cust_address | char(50)  | YES  |     | NULL                  |

    | cust_city    | char(50)  | YES  |     | NULL                  |

    | cust_state   | char(5)   | YES  |     | NULL                  |

    | cust_zip     | char(10)  | YES  |     | NULL                  |

    | cust_country | char(50)  | YES  |     | NULL                  |

    | cust_contact | char(50)  | YES  |     | NULL                  |

    | cust_email   | char(255) | YES  |     | NULL                  |

    +--------------+-----------+------+-----+---------+----------------+

     

    9 rows in set (0.00 sec)

    (jlive)[crashcourse]>INSERT INTO customers VALUES(NULL, 'Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA', NULL, NULL);

    (jlive)[crashcourse]>SELECT cust_name,cust_address,cust_city,cust_state,cust_zip FROM customers;

    +----------------+---------------------+-------------+------------+----------+

    | cust_name      | cust_address        | cust_city   | cust_state | cust_zip |

    +----------------+---------------------+-------------+------------+----------+

    | Coyote Inc.    | 200 Maple Lane      | Detroit     | MI         | 44444    |

    | Mouse House    | 333 Fromage Lane    | Columbus    | OH         | 43333    |

    | Wascals        | 1 Sunny Place       | Muncie      | IN         | 42222    |

    | Yosemite Place | 829 Riverside Drive | Phoenix     | AZ         | 88888    |

    | E Fudd         | 4545 53rd Street    | Chicago     | IL         | 54545    |

    | Pep E. LaPew   | 100 Main Street     | Los Angeles | CA         | 90046    |

    +----------------+---------------------+-------------+------------+----------+

     

    6 rows in set (0.15 sec)


    插入一行中的某几个字段

    (jlive)[crashcourse]>INSERT INTO customers(cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email) VALUES('Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA', NULL, NULL);

     

    Query OK, 1 row affected (0.00 sec)


    一条插入语句插入多条数据

    INSERT INTO customers(cust_name,cust_address, cust_city, cust_state, cust_zip, cust_country)

    VALUES

    ('Pep E. LaPew','100 Main Street', 'Los Angeles', 'CA','90046','USA' ),

    ('M. Martian', '42 Galaxy Way', 'New York', 'NY','11213','USA')


    插入查询到的数据

    INSERT INTO customers(cust_id,cust_contact, cust_email, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country)

    SELECT cust_id, cust_contact,cust_email, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country FROM custnew


    UPDATE

    (jlive)[crashcourse]>UPDATE customers SET cust_name = 'The Fudds', cust_email = 'elmer@fuddd.com' WHERE cust_id = 10005;

    Query OK, 1 row affected (0.00 sec)

    Rows matched: 1  Changed: 1  Warnings: 0


    (jlive)[crashcourse]>SELECT cust_id, cust_name, cust_email FROM customers WHERE cust_id = 10005;

    +---------+-----------+-----------------+

    | cust_id | cust_name | cust_email      |

    +---------+-----------+-----------------+

    |   10005 | The Fudds | elmer@fuddd.com |

    +---------+-----------+-----------------+

     

    1 row in set (0.00 sec)

    (jlive)[crashcourse]>UPDATE customers SET cust_email = NULL WHERE cust_id = 10005;

    Query OK, 0 rows affected (0.00 sec)

    Rows matched: 1  Changed: 0  Warnings: 0


    (jlive)[crashcourse]>SELECT cust_id, cust_name, cust_email FROM customers WHERE cust_id = 10005;

    +---------+-----------+------------+

    | cust_id | cust_name | cust_email |

    +---------+-----------+------------+

    |   10005 | The Fudds | NULL       |

    +---------+-----------+------------+

     

    1 row in set (0.00 sec)




    DELETE

    (jlive)[crashcourse]>DELETE FROM customers WHERE cust_id = 10006;

     

    Query OK, 1 row affected (0.00 sec)

  • 相关阅读:
    hystrix 源码分析以及属性的配置
    golang官方包限流器使用和原理(golang.org/x/time/rate)
    pip通过指定分支和子目录从git仓库中拉取python包
    cgo使用示例总结
    python装饰器原理和用法总结
    centos7编译安装clang8(同时还会编译llvm的不少东西, 文中附带编译好的二进制压缩包)
    prometheus+alertmanager+granafa监控总结,安装基于docker-compose(长期更新)
    go条件变量的使用和原理
    canal+kafka订阅Mysql binlog将数据异构到elasticsearch(或其他存储方式)
    go对elasticsearch的增删改查
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814176.html
Copyright © 2011-2022 走看看