前言
簡單記錄insert命令的使用
用法
-
insert into
INSERT INTO student(NAME, salary, created_at) VALUES('xing', 900, CURDATE());
-
insert into values
- 需要添加所有列的值
INSERT INTO student VALUES(DEFAULT, 'xing', 900, CURDATE());
-
insert into select from
- 通常用於處理數據后插入已存在的表
- insert into中的列數量必須和select的保持一致,否則會報錯的
INSERT INTO GoodsUrl (
id,
url,
created_at,
updated_at
) SELECT
Goods.id AS id,
CONCAT_WS(
'/',
Domains.`name`,
Goods.sitedir
) AS url,
Goods.created_at AS created_at,
Goods.updated_at AS updated_at
FROM
Goods,
Domains
WHERE
Goods.domain_id = Domains.id
AND Goods.is_domain = 0
-
create table newtb (selct from)
- 通常用於復制表數據
- 新表newtb必須是不存在的表,否則會報錯
- 該語法解釋時會報錯,但不影響執行
CREATE TABLE student3 (
SELECT
NAME,
salary
FROM
student
);
