먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,FirstName varchar(100)); Query OK, 0 rows affected (0.70 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstName) values('Robert'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName) values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(FirstName) values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName) values('Carol'); Query OK, 1 row affected (0.12 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Mike | | 5 | Adam | | 6 Carol | +----+-----------+ 6 rows in set (0.00 sec)
다음은 auto_increment −
로 주문하는 쿼리입니다.mysql> select *from DemoTable order by Id DESC;
이것은 다음과 같은 출력을 생성합니다 -
+----+-----------+ | Id | FirstName | +----+-----------+ | 6 | Carol | | 5 | Adam | | 4 | Mike | | 3 | David | | 2 | Robert | | 1 | Chris | +----+-----------+ 6 rows in set (0.00 sec)