| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 大数据 -> SQL: INSERT Statement -> 正文阅读 |
|
[大数据]SQL: INSERT Statement |
SQL: INSERT StatementThe SQL INSERT statement allows you to insert a single record or multiple records into a table. The syntax for the SQL INSERT statement is: INSERT INTO table
(column-1, column-2, ... column-n)
VALUES
(value-1, value-2, ... value-n);
SQL INSERT Statement - Using VALUES keyword exampleThe simplest way to create an SQL INSERT statement to list the values using the VALUES keyword. For example: INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(24553, 'IBM');
This SQL INSERT statement would result in one record being inserted into the suppliers table. This new record would have a supplier_id of 24553 and a supplier_name of IBM. SQL INSERT Statement - Using sub-selects exampleYou can also create more complicated SQL INSERT statements using sub-selects. For example: INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE city = 'Newark';
By placing a "select" in the SQL INSERT statement, you can perform multiples inserts quickly. With this type of insert, you may wish to check for the number of rows being inserted. You can determine the number of rows that will be inserted by running the following SQL SELECT statement?before?performing the insert. SELECT count(*)
FROM customers
WHERE city = 'Newark';
Frequently Asked QuestionsQuestion:?I am setting up a database with clients. I know that you use the SQL INSERT statement to insert information in the database, but how do I make sure that I do not enter the same client information again? Answer:?You can make sure that you do not insert duplicate information by using the?SQL EXISTS condition. For example, if you had a table named?clients?with a primary key of?client_id, you could use the following SQL INSERT statement: INSERT INTO clients
(client_id, client_name, client_type)
SELECT supplier_id, supplier_name, 'advertising'
FROM suppliers
WHERE not exists (select * from clients
????????????????? where clients.client_id = suppliers.supplier_id);
This SQL INSERT statement inserts multiple records with a subselect. If you wanted to insert a single record, you could use the following SQL INSERT statement: INSERT INTO clients
(client_id, client_name, client_type)
SELECT 10345, 'IBM', 'advertising'
FROM dual
WHERE not exists (select * from clients
????????????????? where clients.client_id = 10345);
The use of the?dual?table allows you to enter your values in a select statement, even though the values are not currently stored in a table. Question:?How can I insert multiple rows of explicit data in one SQL command in Oracle? Answer:?The following is an example of how you might insert 3 rows into the?suppliers?table in Oracle, using an SQL INSERT statement: INSERT ALL
? INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
? INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
? INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
SELECT * FROM dual;
|
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/24 11:33:36- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |