다중 삽입을 수행하기 위한 구문은 다음과 같습니다 -
insert into yourTableName(yourColumnName1,yourColumnName2,yourColumnName3,..N) select yourValue1 as yourColumnName1,yourValue2 as yourColumnName2,yourValue3 as yourColumnName3,......N union select yourValue1 as yourColumnName1,yourValue2 as yourColumnName2,yourValue3 as yourColumnName3,......N . . N
위의 구문을 이해하기 위해 테이블을 만들어 보겠습니다 -
mysql> create table DemoTable1936 ( StudentId int, StudentName varchar(20), StudentCountryName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1936(StudentId,StudentName,StudentCountryName) select 1001 as StudentId,'Chris' as StudentName,'US' as StudentCountryName union select 1002 as StudentId,'Robert' as StudentName,'UK' as StudentCountryName union select 1003 as StudentId,'David' as StudentName,'AUS' as StudentCountryName; Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1936;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | 1001 | Chris | US | | 1002 | Robert | UK | | 1003 | David | AUS | +-----------+-------------+--------------------+ 3 rows in set (0.00 sec)