본문 바로가기

웹개발/mysql

[mysql]컬럼추가제거(alter)

반응형

컬럼추가제거(alter)


컬럼추가

alter table "테이블명" add "컬럼이름" "데이터타입" "옵션";


컬럼제거

alter table "테이블명" drop "컬럼명";



ex)

1) 현재 테이블 정보 확인

show create table test;


CREATE TABLE `test` (

  `name` varchar(10) default NULL,

  `num` int(1) NOT NULL auto_increment,

  PRIMARY KEY  (`num`)

) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8


2) 컬럼추가 명령어 실행

alter table test add uid int(4) not null default 0;


3) 변경된 테이블정보 확인

show create table test;


CREATE TABLE `test` (

  `name` varchar(10) default NULL,

  `num` int(1) NOT NULL auto_increment,

  `uid` int(4) NOT NULL default '0',

  PRIMARY KEY  (`num`)

) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 


4) 컬럼삭제 명령어 실행

alter table test drop uid;


5) 변경된 테이블정보 확인

show create table test;

CREATE TABLE `test` (

  `name` varchar(10) default NULL,

  `num` int(1) NOT NULL auto_increment,

  PRIMARY KEY  (`num`)

) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8

반응형

'웹개발 > mysql' 카테고리의 다른 글

[mysql]데이터베이스 백업/복구  (0) 2014.07.10
[mysql]중복제거(group by)  (0) 2013.12.15
[mysql]최소값,최대값(min,max)  (0) 2013.12.15
[mysql]테이블 정보확인하기  (0) 2013.12.09
[mysql] 중복값 제거 (Distinct)  (0) 2013.11.26