2
How do I insert several values into a table, but into a single one query of sql?
2
How do I insert several values into a table, but into a single one query of sql?
8
INSERT INTO TESTE VALUES (1,'ABACAXI'), (2,'BATATA');
Examples:
SQL Server
in the SQL Fiddle.
MySQL
in the SQL Fiddle.
PostgreSQL
in the SQL Fiddle.
You can use the INSERT ALL
:
INSERT ALL
INTO TESTE VALUES (1,'ABACAXI')
INTO TESTE VALUES (2,'BATATA')
SELECT 1 FROM DUAL;
See working on SQL Fiddle.
db.teste.insert([
{"id": 1, nome: "ABACAXI"},
{"id": 2, nome: "BATATA"}
]);
As did not inform the SGDB put the main ones, if not the case, I update later.
By the way, mariaDB, postgres and nosql :)
0
With Sql Server, 2 suggestions:
declare @sql nvarchar(max)
set @sql = N'insert into tabela (coluna1, coluna2) values (''coluna1'', ''coluna2'');
insert into tabela (coluna1, coluna2) values (''coluna1'', ''coluna2'');
insert into tabela (coluna1, coluna2) values (''coluna1'', ''coluna2'');'
exec sp_executesql @sql
or
insert into tabela (coluna1, coluna2)
select coluna1, coluna2 from tabela2
Browser other questions tagged sql
You are not signed in. Login or sign up in order to post.
What would be the
SGDB
?– Homer Simpson
DBMS stands for Database Management System just in case you don’t know :/ for example Mysql is a DBMS
– IdkWhy