먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name) values('Adam'); Query OK, 1 row affected (0.18 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
출력
+----+--------+ | Id | Name | +----+--------+ | 1 | Carol | | 2 | Chris | | 3 | David | | 4 | Bob | | 5 | Mike | | 6 | Sam | | 7 | Robert | | 8 | Adam | +----+--------+ 8 rows in set (0.00 sec)
다음은 테이블을 업데이트하고 마지막 열 값을 제외하고 동일한 값으로 열을 설정하는 쿼리입니다 -
mysql> update DemoTable -> set Name="John" -> limit 7; Query OK, 7 rows affected (0.20 sec) Rows matched: 7 Changed: 7 Warnings: 0
다시 한번 테이블 기록을 확인해보자.
mysql> select *from DemoTable;
출력
+----+------+ | Id | Name | +----+------+ | 1 | John | | 2 | John | | 3 | John | | 4 | John | | 5 | John | | 6 | John | | 7 | John | | 8 | Adam | +----+------+ 8 rows in set (0.00 sec)