T

ALTER 테이블 추가,변경

ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]

alter_specification:

ADD [COLUMN] create_definition [FIRST | AFTER column_name ]

or ADD [COLUMN] (create_definition, create_definition,...)

or ADD INDEX [index_name] (index_col_name,...)

or ADD PRIMARY KEY (index_col_name,...)

or ADD UNIQUE [index_name] (index_col_name,...)

or ADD FULLTEXT [index_name] (index_col_name,...)

or ADD [CONSTRAINT symbol] FOREIGN KEY index_name (index_col_name,...) [reference_definition]

or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}

or CHANGE [COLUMN] old_col_name create_definition [FIRST | AFTER column_name]

or MODIFY [COLUMN] create_definition [FIRST | AFTER column_name]

or DROP [COLUMN] col_name

or DROP PRIMARY KEY

or DROP INDEX index_name

or DISABLE KEYS

or ENABLE KEYS

or RENAME [TO] new_tbl_name

or ORDER BY col

or table_options





% 필드 추가하기

mysql> alter table 테이블 add column 필드명 데이타형;

% 두개의 필드 추가하기

mysql> alter table 테이블 add column wdate,add column wtime time;

wdate date 날짜데이터 형
wtime time 시간데이터 형

% 한라인 입력
mysql>create table test(..............);

% 다중입력
mysql>create table test(
->num
->int,
->name
->varchar(10));
%필드 수정하기

alter table 테이블이름 rename 바꿀이름


% 필드 삭제

alter table 테이블명 drop 칼럼네임






-----------------------------------------------------------

새로운 필드 삽입시 이미 만들어진 필드 의 어느 부분에 넣으려고 합니다.

add lolumn 추가하려는 필드명 [first/after 필드명]이라구 적혀있더라구요..

alter table insa add column address char(20) first name;

이렇게 하니 에러가 나내요..어떻게 써야 하나요....

답변좀 부탁드립니다. 그럼감사..고맙습니다.


[답변]---------------------------------------------->

예로서 설명을 해드리지요...

------------------------------------
| filed | type | key | default |
------------------------------------
| year | int(11) | pri | 0 |
------------------------------------
| name |varchar(8)| pri | 0 |
------------------------------------


뭐 이런식으로 db 디자인이 되어있다면...

여기다가 first/alter 를 이용하여 어느앞..어느뒤에다 넣을 것인지 쳐주면 됩니다...


그러니까...이 테이블 이름이 님의 테이블처럼 insa 경우..

alter table [테이블이름] add [컬럼정의부분] first;

->alter table insa add class int not null first;


이렇게 쳐주시면 class라는 컬럼이 테이블 최상위로 올라간답니다.


또 alter table insa add class int not null after year;


이렇게 쳐주시면 year라는 컬럼뒤에 class라는 컬럼이 추가 되겠지요...^^

제가 투덜이 책을 안봐서 모르겠지만...

설명이 잘 되었으리라 생각이 듭니다...


마지막으로 설마하는 맘으로...

님의 경우에서 한번더 써드리지요...


님이 쓰신글 -> alter table insa add column address char(20) first name;


수정한 글 -> alter table insa add address char(20) first;

[테이블명] [컬럼명][컬럼타입]


이렇게 써주셔야...테이블 최상위로 올라갑니다..^^

만약 name이라는 컬럼 뒤에 넣고 싶다면...


-> alter table insa add address char(20) after name;<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:27:00 MySQL에서 이동 됨]</div>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
20년 전 조회 3,651
20년 전 조회 2,968
20년 전 조회 2,093
20년 전 조회 1만
20년 전 조회 2,232
20년 전 조회 1,577
20년 전 조회 2,650
20년 전 조회 2,265
20년 전 조회 1,661
20년 전 조회 1,464
20년 전 조회 1,891
20년 전 조회 1,689
20년 전 조회 1,723
20년 전 조회 2,335
20년 전 조회 1,540
20년 전 조회 1,480
20년 전 조회 1,622
20년 전 조회 2,716
20년 전 조회 1,789
20년 전 조회 1,844
20년 전 조회 1,971
20년 전 조회 1,796
20년 전 조회 1,871
20년 전 조회 1,689
20년 전 조회 2,060
20년 전 조회 1,777
20년 전 조회 2,552
20년 전 조회 2,258
20년 전 조회 2,543
20년 전 조회 1,475
20년 전 조회 1,573
20년 전 조회 2,148
20년 전 조회 1,609
20년 전 조회 3,741
20년 전 조회 2,629
20년 전 조회 2,065
20년 전 조회 2,768
20년 전 조회 1,723
20년 전 조회 1,595
20년 전 조회 2,545
20년 전 조회 1,467
20년 전 조회 1,713
20년 전 조회 3,214
20년 전 조회 1,866
20년 전 조회 1,593
20년 전 조회 4,925
20년 전 조회 4,561
20년 전 조회 3,501
20년 전 조회 3,768
20년 전 조회 7,047
20년 전 조회 3,537
20년 전 조회 2,602
20년 전 조회 2,598
20년 전 조회 7,155
20년 전 조회 4,569
20년 전 조회 1,876
20년 전 조회 3,234
20년 전 조회 1,934
20년 전 조회 1,539
20년 전 조회 2,285
20년 전 조회 1,774
20년 전 조회 1,447
20년 전 조회 1,787
20년 전 조회 2,956
20년 전 조회 2,432
20년 전 조회 1,711
20년 전 조회 1,636
20년 전 조회 3,965
20년 전 조회 2,907
20년 전 조회 3,629
20년 전 조회 3,422
20년 전 조회 3,729
20년 전 조회 8,556
20년 전 조회 2,580
21년 전 조회 3,737
21년 전 조회 3,185
21년 전 조회 2,585
21년 전 조회 2,653
21년 전 조회 2,565
21년 전 조회 2,845
21년 전 조회 3,020
21년 전 조회 5,289
21년 전 조회 3,892
21년 전 조회 4,939
21년 전 조회 6,192
21년 전 조회 7,319
21년 전 조회 1.8만
21년 전 조회 6,861
21년 전 조회 2,864
21년 전 조회 4,121
21년 전 조회 2,466
21년 전 조회 4,292
21년 전 조회 2,883
21년 전 조회 2,239
21년 전 조회 2,454
21년 전 조회 2,215
21년 전 조회 2,549
21년 전 조회 1,723
21년 전 조회 1,560
21년 전 조회 1,611