当前位置:网站首页>SQL INSERT INTO and INSERT INTO the SELECT statement
SQL INSERT INTO and INSERT INTO the SELECT statement
2022-08-08 12:32:00 【night drift ice】
The INSERT INTO statement is used to insert records of information into a table.
Syntax:
The first type, specify the column name and the inserted value
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, valu23, ...);
Second, if all the columns in the table are present, it is not necessary to specify the name of the column in the SQL query.But the order of the values should be the same as the order of the columns in the table.
INSERT INTO table_name
VALUES (value1, value2, value3, ...)
Example:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway')
The INSERT INTO SELECT statement copies data from one table and adds it to another table.
When operating, make sure that the type of the copied data matches the data type of the table to be inserted.
This operation does not affect other data in the destination table.
Syntax:
Copy all data from one table to another.
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
Copy several columns of data from one table to another:
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
Example:
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;
Insert the result of a Union into a table:
INSERT INTO Team (name, age)
SELECT customer_name AS name, 21 AS age FROM Customers WHERE customer_id IS NOT NULL
UNION
SELECT customer_name, 31 FROM Orders
ORDER BY name;
Get the customer name from the first table, and a fixed number, and the second table, too, and then combine.Then insert into another table.
Reference:
边栏推荐
猜你喜欢
深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)

RT-Thread记录(三、RT-Thread 线程操作函数及线程管理与FreeRTOS的比较)

字节跳动资深架构师整理2022年秋招最新面试题汇总:208页核心体系

#yyds干货盘点#【愚公系列】2022年08月 Go教学课程 005-变量

详解轮播图二-通过left定位来轮播图片

Mysql的分布式事务原理理解

皕杰报表之数据校验与处理

论文阅读《Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras》

Study: Toxic PFAS chemicals make rainwater unsafe to drink around the world

如何在go重打印函数调用者信息Caller
随机推荐
GC explanation and tuning of JVM
内网渗透学习(五)域横向移动——PTH&PTK&PTT
day02 -DOM - advanced events (register events, event listeners, delete events, DOM event flow, event objects, prevent default behavior, prevent event bubbling, event delegation) - commonly used mouse
Collection of shell basics
leetcode-636:函数的独占时间
动图图解!既然IP层会分片,为什么TCP层也还要分段?
Mysql索引优化实战
MeterSphere--开源持续测试平台
面试突击72:输入URL之后会执行什么流程?
软件测试之测试代表用户
如何使用shell来进行版本管理-以iptables为例
刷题《剑指Offer》day12
开放原子开源峰会 - SmartIDE正式开源并发布v1.0版本
一文读懂配置管理(CM)
产品-Axure9英文版,下拉框Droplist的条件选择,显示不同内容面板
神经网络分类
Replication监控及自动故障切换
node中package解析、npm 命令行npm详解,node中的common模块化,npm、nrm两种方式查看源和切换镜像
一文读懂配置管理(CM)
office安装出现了“office对安装源的访问被拒绝30068-4(5)”错误