赞
踩
目录
INSERT INTO table_name
VALUES (value1, value2, ...)
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...)
INSERT INTO table_name (column1, column2, ...)
VALUES (value1_1, value1_2, ...), (value2_1, value2_2, ...), ...
INSERT INTO table_name
SELECT * FROM table_name2
[WHERE key=value]
插入所有行
- INSERR INTO 表名 VALUES (' ',' ' ...)
插入部分行
- INSERT INTO 表名( '各个列名' ) VALUES ( '各个赋值 ')
写明各个列名,是为了原表顺序改变,改语句也不会受影响
e.g. 将一个顾客插入到customers表,每一列都按照列顺序提供一个值,如该列没有对应值,用null
- INSERT INTO customers
- VALUES ('1006',
- 'TOY',
- 'NEW YORK',
- NULL,
- NULL );
e.g. 将驾驶里程drivedistanced超过5000里的四级信息,转存到另一张seniordrivers表中,他们的详细情况记录的原表为drivers
- select *
- into seniordrives
- from drivers
- where drivedistanced>=5000;
即在insert语句中,嵌套select语句
e.g 把custnew表的顾客列对应值,合并到customers 表
- INSERT INTO customers(cust_id,
- cust_contact,
- cust_email)
- SELECT cust_id,cust_contact,cust_email
- FROM custnew;
形式: CREATE 新表名 AS SELECT 列 FROM 原表
e.g.从创建一个叫做custcopy的新表,把customers表的所有值复制过去
- CREATE TABLE custcopy AS
- SELECT * FROM custmers;
UPDATE 要更新的表名
SET 要更新的列名 = ‘新赋值内容’
WHRER 限定条件语句;
e.g1. 设置给id是1001的cust_email新的赋值
- UPDATE customers
- SET cust_email = '333@ew.com'
- WHERE cust_id = 1001;
e.g2. 多列更新
- UPDATE customers
- SET cust_contact ='aa',
- cust_email = 'ww@.esd.com'
- WHERE cust_id = 1001;
e.g3. 删除某列的值,即将其赋值为null (删除某行,用delete)
- UPDATE customers
- SET cust_contact IS NULL
- WHERE cust_id = '1001';
e.g4. 将type列中,是tool的序号都减2,序号列为shelf
- update books
- set shelf=shelf-2
- where type='tool';
REPLACE INTO 表名(字段1,字段2,...)
VALUES(赋值1,赋值2);
同样用于更新数据,但可以先检索原表有无同样的数据,如果有可以作为替换更新,不会报错
DELETE FROM 要删除数据的表名
WHERE语句限定要删除的行;
e.g. 删除cust_id是1001的整行
- DELETE FROM customers
- WHERE cust_id=1001;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。