강좌
클라우드/리눅스에 관한 강좌입니다.
데이터베이스 분류

기존의 필드삭제하기(alter table)

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

기존의 필드삭제하기(alter table)

 

 

 

 

 

불필요한 필드를 삭제할 수도 있다.

 

 

 

 

 앞에서 생성했던 website라는 필드를 삭제해보도록 하겠다.

 

 

 

 

 삭제하는 명령의 형식은 다음과 같다.

 

 

 

 

 

 

ALTER TABLE 테이블명 DROP [COLUMN] 필드명

 

다음예는 testtable에 존재했던 website라는 필드를 삭제한 것이다.

 

 

 

 

 

 

[root@RockyLinux wpDB]# mysql -u root -p TESTDB

Enter password:

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 43

Server version: 10.5.16-MariaDB MariaDB Server

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [TESTDB]>

MariaDB [TESTDB]> desc testtable;

+---------+-----------------------+------+-----+---------+-------+

| Field   | Type                  | Null | Key | Default | Extra |

+---------+-----------------------+------+-----+---------+-------+

| uid     | mediumint(4) unsigned | NO   | PRI | 0       |       |

| name    | varchar(12)           | NO   |     |         |       |

| email   | varchar(20)           | NO   |     |         |       |

| website | varchar(50)           | YES  |     | NULL    |       |

+---------+-----------------------+------+-----+---------+-------+

4 rows in set (0.001 sec)

 

MariaDB [TESTDB]>

MariaDB [TESTDB]> alter table testtable drop column website;

Query OK, 0 rows affected (0.010 sec)

Records: 0  Duplicates: 0  Warnings: 0

 

MariaDB [TESTDB]>

 

그리고 다음은 그 결과를 확인하기 위하여 “desc testtable”을 실행한 예이다.

 

 

 

 

 

 

MariaDB [TESTDB]> desc testtable;

+-------+-----------------------+------+-----+---------+-------+

| Field | Type                  | Null | Key | Default | Extra |

+-------+-----------------------+------+-----+---------+-------+

| uid   | mediumint(4) unsigned | NO   | PRI | 0       |       |

| name  | varchar(12)           | NO   |     |         |       |

| email | varchar(20)           | NO   |     |         |       |

+-------+-----------------------+------+-----+---------+-------+

3 rows in set (0.001 sec)

 

MariaDB [TESTDB]>

 

위의 결과를 보면 기존에 존재하고있었던 website라는 필드가 삭제되었음을 알 수 있다.

 

 

 

 

  이와같이 기존의 필드속성을 변경(수정,삭제등)할 수 있다는 것을 알아 보았다.

 

 

 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,037 명
  • 현재 강좌수 :  35,806 개
  • 현재 접속자 :  145 명