Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

MySQL에서 CHANGE 명령을 사용하는 목적은 무엇입니까?


MySQL의 CHANGE 명령은 열 이름을 바꾸는 데 사용됩니다. 먼저 테이블을 생성하겠습니다 -

mysql> create table DemoTable796 (
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,Name varchar(100),StudentAge int
);
Query OK, 0 rows affected (0.56 sec)

테이블 설명을 확인해보자 -

mysql> desc DemoTable796;

이것은 다음과 같은 출력을 생성합니다 -

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| StudentId  | int(11)      | NO   | PRI | NULL    | auto_increment |
| Name       | varchar(100) | YES  |     | NULL    |                |
| StudentAge | int(11)      | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

다음은 MySQL에서 CHANGE 명령을 사용하는 쿼리입니다 -

mysql> alter table DemoTable796 change Name StudentName varchar(100);
Query OK, 0 rows affected (0.29 sec)
Records: 0 Duplicates: 0 Warnings: 0

다시 한번 테이블 설명을 확인해보자 -

mysql> desc DemoTable796;

이것은 다음과 같은 출력을 생성합니다 -

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| StudentId   | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentName | varchar(100) | YES  |     | NULL    |                |
| StudentAge  | int(11)      | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)