登录 | 首页 -> 华新鲜事 -> 求学狮城 | 切换到:传统版 / sForum | 树形列表
in mysql...
<<始页  [1]  末页>> 

in mysql...改一个column的属性怎样改?如果该column是primary key呢?

比方说从varchar(20)改为numeric(20)...


谢了!
[小蹦 (9-28 1:22, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

小蹦请进suppose u want to change column a in table t, from varchar(20) to numeric(20) and change its name from a to b,
u can use

ALTER TABLE t CHANGE a b numeric(20);

value in the column will be truncated, if the memory of new type is not big enough to store this value;


As for primary key, if u want to change its type from one to another, u should make sure that there won't be two duplicate value in that column after u do the transformation. otherwise, it will refuse to do the job
[我行故我 (9-28 18:24, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

(引用 我行故我:小蹦请进suppose u want to change column a in table t, from varchar(20) to numeric(20) and change its name from a to b, u can use...)不行也。。。i use: ALTER TABLE t CHANGE a a numeric(20);

got error: All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead..

why? is it because the field 'a' is a primary key?
[小蹦 (9-28 19:13, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

(引用 小蹦:不行也。。。i use: ALTER TABLE t CHANGE a a numeric(20); got error: All parts of a PRIMARY KEY must be NOT NULL; If you need N...)how come this error appear,...after u do the altering????


do u have any null value which is ur primary key ?
[我行故我 (9-28 21:08, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼

(引用 我行故我:how come this error appear,...after u do the altering???? do u have any null value which is ur primary key ?)没有啊。。。id就是1, 10, 100, 101共四个。。。[小蹦 (9-28 22:24, Long long ago)] [ 传统版 | sForum ][登录后回复]5楼

(引用 小蹦:没有啊。。。id就是1, 10, 100, 101共四个。。。)then you drop that table and re-design it carefully lah[MrDJay (9-29 15:26, Long long ago)] [ 传统版 | sForum ][登录后回复]6楼

(引用 小蹦:不行也。。。i use: ALTER TABLE t CHANGE a a numeric(20); got error: All parts of a PRIMARY KEY must be NOT NULL; If you need N...)Why there are two a's there?You don't need two.[Flying (9-29 15:57, Long long ago)] [ 传统版 | sForum ][登录后回复]7楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 求学狮城 | [刷新本页] | 切换到:传统版 / sForum