먼저 데모 테이블을 생성하겠습니다 -
mysql> create table BulkChangeDemo -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(20), -> isEducated boolean -> ); Query OK, 0 rows affected (1.47 sec)
삽입 명령을 사용하여 테이블에 일부 레코드를 삽입하십시오. 쿼리는 다음과 같습니다 -
mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('Larry',true); Query OK, 1 row affected (0.09 sec) mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('John',false); Query OK, 1 row affected (0.16 sec) mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('Carol',false); Query OK, 1 row affected (0.25 sec) mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('Mike',true); Query OK, 1 row affected (0.18 sec) mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('David',false); Query OK, 1 row affected (0.13 sec) mysql> insert into BulkChangeDemo(CustomerName,isEducated) values('Bob',false); Query OK, 1 row affected (0.10 sec)
select 문을 사용하여 테이블의 모든 레코드를 표시합니다. 쿼리는 다음과 같습니다 -
mysql> select *from BulkChangeDemo;
다음은 출력입니다 -
+------------+--------------+------------+ | CustomerId | CustomerName | isEducated | +------------+--------------+------------+ | 1 | Larry | 1 | | 2 | John | 0 | | 3 | Carol | 0 | | 4 | Mike | 1 | | 5 | David | 0 | | 6 | Bob | 0 | +------------+--------------+------------+ 6 rows in set (0.00 sec)
다음은 특정 필드의 모든 항목을 일괄 변경하는 쿼리입니다 -
mysql> update BulkChangeDemo set isEducated =true; Query OK, 4 rows affected (0.18 sec) Rows matched: 6 Changed: 4 Warnings: 0