http://www.111cn.net/database/mysql/50678.htm
下面为您介绍的sql语句都是mysql修改字段操作中的一些常用语句,如果您是一个刚刚接触mysql数据库的新手,不妨一看,对您学习mysql修改字段方面会大有裨益。
mysql修改字段的默认值
alter table tb_mer_team_column drop constraint DF_tb_mer_team_column_columnOrder
alter table tb_mer_team_column add constraint DF_tb_mer_team_column_columnOrder default 0 for columnOrder
sql 语句添加字段
alter table table1(表名)add No_id(字段名) char(12)(字段类型) t null | null UNIQUE after '字符' 在制定字段后面添加
mysql修改字段类型
ALTER TABLE `family` CHANGE `text` `text` varchar(90) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '家族公告'
//////////////alter table t1(表名) alter column a(字段名) text(50)(字段类型)
sql 添加主键 字段
alter table tb_mer_basInfo add constraint [PK_tb_merchantBasInfo] primary key ( merchantID)
sql 删除某表的字段
alter table `lm_aclass` drop 'cpid'
显示某个表创建时的全部信息:
show create table table_name;
查看表的具体属性信息及表中各字段的描述:
Describe table_name;
缩写形式 : desc table_name;
OR
show columns from table_name;
mysql> show columns from test.people;
+------------------+-------------------+-------+------+---------+---------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------------+-------+------+---------+---------------------+
| people_id | int(9) unsigned | NO | PRI | NULL | auto_increment |
| people_name | varchar(16) | NO | | NULL | |
+------------------+-------------------+-------+------+---------+---------------------+
2 rows in set (0.02 sec)
以十六进制显示字段的值
select people_id, hex(people_name) from test.people;
+-------------+-------------------------+
| people_id | hex(people_name) |
+-------------+-------------------------+
| 1 | D5C5C8FD |
+-------------+-------------------------+
| 2 | C0EECBC4 |
+-------------+-------------------------+