赞
踩
目录
INSERT INTO 表(列名1,列名2,列名3... ...) VALUES (值1,值2, 值3.....)//一组括号代表一行数据
DESC 表; // 查询表结构
INSERT INTO 表(列名1) VALUES (值1),(值2),( 值3).....;
INSERT INTO 库名.表名(列名列表)VALUES(值列表);
VALUES(值列表),(值列表),...INSERT INTO 库名,表名(列名列表);
set命令赋值
INSERT INTO 库名:表名 SET 字段=值,字段=值 ,.......;
批量修改
UPDATE库名.表名 SET 字段=值,字段=值,
仅修改与条件匹配的
UPDATE库名.表名 SET 字段=值,字段=值 WHERE 条件;
DELETE FROM 库名.表名 WHERE 条件; //仅删除与条件匹配的行
DELETE FROM 库名.表名; //清空表记录
TRUNCATE TABLE 库名.表名; //清空表记录
1、使用 INSERT 和指定的列,将自己添加到 Customers 表中。
- mysql> INSERT INTO customers(cust_id,
- -> cust_name,
- -> cust_address,
- -> cust_city,
- -> cust_state,
- -> cust_zip,
- -> cust_country,
- -> cust_email)
- -> VALUES(10042,
- -> 'Qzb',
- -> '123 Main Street',
- -> 'Oak Park',
- -> 'MI',
- -> '48237',
- -> 'China',
- -> 'ben@fortabbwpc.wpcomstaging.com');
- Query OK, 1 row affected (0.00 sec)
2、创建 Orders 和 OrderItems 表的备份副本。
- ysql> CREATE TABLE ordersBackup AS SELECT * FROM orders;;
- Query OK, 5 rows affected (0.08 sec)
- Records: 5 Duplicates: 0 Warnings: 0
-
- mysql> CREATE TABLE orderitemsBackup AS SELECT * FROM orderitems;
- Query OK, 11 rows affected (0.02 sec)
- Records: 11 Duplicates: 0 Warnings: 0
3、美国州的缩写应始终为大写。编写 SQL 语句以更新所有美国地址,包括供应商状态(供应商中的vend_state)和客户状态(客户中的cust_state),使它们为大写。
- mysql> UPDATE vendors SET vend_state = UPPER(vend_state) WHERE vend_country = 'USA';
- Query OK, 0 rows affected (0.01 sec)
- Rows matched: 4 Changed: 0 Warnings: 0
-
- mysql> UPDATE customers SET cust_state = UPPER(cust_state) WHERE cust_country = 'USA';
- Query OK, 0 rows affected (0.00 sec)
- Rows matched: 5 Changed: 0 Warnings: 0
4、我要求您将自己添加到 Customers 表中。现在删除你自己。请确保使用 WHERE 子句(并在 DELETE 中使用 SELECT 之前对其进行测试),否则将删除所有客户!
- mysql> delete from customers where cust_id = 10042;
- Query OK, 1 row affected (0.02 sec)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。