mysql sql语句修改字段长度
+ k7 w' V0 `) W6 i语法: ALTER TABLE 表名 MODIFY COLUMN 字段名 数据类型(修改后的长度) alter table 表名 modify column 字段名 数据类型(修改后的长度) 要修改Type参数 mysql> desc sl;3 ^! q. B; P% ` N0 ]
+-------+---------+------+-----+---------+-------+
) N& @7 l; y1 j| Field | Type | Null | Key | Default | Extra |, a( r) j* t2 M6 C
+-------+---------+------+-----+---------+-------+6 |$ ]% C- t; ?& L P
| name | char(1) | YES | | NULL | | % [- S$ r3 n5 `) \3 y
| sex | char(1) | YES | | NULL | |
2 z) e8 I7 d4 V$ \| age | int(3) | NO | | NULL | | 3 k6 O. s, H* r G; e) S/ D
+-------+---------+------+-----+---------+-------+) {8 ~/ p G K( Y! Q9 U
3 rows in set (0.00 sec) : a9 r0 w% p$ V( `' s9 b0 P! y
由char(1) 修改成char(10) ( O3 Q8 Z9 o4 D0 V; G( |
mysql> alter table sl modify column name char(10);( ` }4 `+ o. Z7 E$ t+ F0 x+ d& u
Query OK, 4 rows affected (0.19 sec)" t- C3 }# R9 A
Records: 4 Duplicates: 0 Warnings: 0 mysql> alter table sl modify column sex varchar(5);
6 _8 S/ i5 C! E$ g: EQuery OK, 4 rows affected (0.22 sec)
2 p; b! l5 b. V7 z. Q; E) uRecords: 4 Duplicates: 0 Warnings: 0 mysql> desc sl;
+ i7 [0 S2 e+ L+ n: g' X3 h* A' \$ _# G+-------+------------+------+-----+---------+-------+( M5 b( y: S" |1 m+ G t
| Field | Type | Null | Key | Default | Extra |( e. `. Y0 H$ _6 J* G9 S/ U& x
+-------+------------+------+-----+---------+-------+
|6 S( X% ~& A9 C| name | char(10) | YES | | NULL | | : d- z6 N9 p, t$ d5 R6 j7 C- T
| sex | varchar(5) | YES | | NULL | | 2 N7 h: H5 Z$ X9 e) y w
| age | int(3) | NO | | NULL | |
. h: C& N1 I" t# e1 F+-------+------------+------+-----+---------+-------+
& F) ]+ a- d+ L3 rows in set (0.00 sec)
w+ R, _0 o8 w/ e5 u# B7 y把name变成varchar mysql> alter table sl modify column name varchar(10);3 w( i0 q6 `- ?3 x- f _1 n: m
Query OK, 4 rows affected (0.07 sec)
" b. q1 ?, ?) J9 v% H1 h6 c0 oRecords: 4 Duplicates: 0 Warnings: 0 mysql> desc sl;
$ b, I/ u9 T" w! k! B2 {; z+-------+-------------+------+-----+---------+-------+) b" s& H, A6 `; T/ T, c3 A, c3 ^
| Field | Type | Null | Key | Default | Extra | P4 W, v, |) l3 I9 d3 I9 r. r$ C
+-------+-------------+------+-----+---------+-------+1 r* G5 M0 G7 `( I+ I; H9 m
| name | varchar(10) | YES | | NULL | | , M$ M7 C' d. C0 M7 @( u- p2 W2 q
| sex | varchar(5) | YES | | NULL | | - ^. N( i& ~% ^+ J( r
| age | int(3) | NO | | NULL | | # N4 s4 `+ X, d9 a, ~
+-------+-------------+------+-----+---------+-------+, W! O+ ]* _! z# G' q
3 rows in set (0.00 sec)/ ^& C \& g. @1 R
|