Oracle
ALTER TABLE T_USER MODIFY USERNAME VARCHAR2(18);
MySQL
ALTER TABLE T_USER CHANGE USERNAME USERNAME VARCHAR(200) NOT NULL COMMENT 'username';
SQL Server
ALTER TABLE T_USER ALTER COLUMN USERNAME VARCHAR(200);
【注意】SQL Server 字段有约束或者索引,需要按如下方式处理:
- 字段是主键:
1 ALTER TABLE T_USER DROP CONSTRAINT PK_T_USER; 2 ALTER TABLE T_USER ALTER COLUMN ID VARCHAR(20) NOT NULL; 3 ALTER TABLE T_USER ADD CONSTRAINT PK_T_USER PRIMARY KEY (ID);
- 字段有约束,并且修改后字段长度大于原长度:
1 ALTER TABLE T_USER DROP CONSTRAINT UN_T_USER; 2 ALTER TABLE T_USER ALTER COLUMN USERNAME VARCHAR(20); 3 ALTER TABLE T_USER ADD CONSTRAINT UN_T_USER UNIQUE (USERNAME);
- 字段有索引,比如唯一索引,并且修改后字段长度大于原长度:
1 DROP INDEX IDX_USER ON T_USER; 2 ALTER TABLE T_USER ALTER COLUMN USERNAME VARCHAR(20); 3 CREATE INDEX IDX_USER ON T_USER(USERNAME);