• 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)

  • 相关阅读:
    第二天续
    使用git提交本地仓库每次需要输入账号密码的问题解决
    第二天
    开启远程之路
    第一天
    第一步了解并且安装配置
    6
    Algorithms
    Algorithms
    Algorithms
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814176.html
Copyright © 2020-2023  润新知