Alter操作(修改列名,修改列数据类型,增加列,删除列,增加列且设为主键及对默认值操作)
生活随笔
收集整理的这篇文章主要介绍了
Alter操作(修改列名,修改列数据类型,增加列,删除列,增加列且设为主键及对默认值操作)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
一、mysql (增加列,删除列,修改列;增加,删除,修改列的默认值)
增加列,删除列,修改列
1、修改列的数据类型
alter table patient modify column mood int2、修改列名
alter table patient change mood address VARCHAR(400)3、删除列
alter table patient drop column mood4、增加列
alter table patient add column mood VARCHAR(400)5、增加列为主键
alter table patient add column id BIGINT not null PRIMARY KEY auto_increment first6、将已有的列设置为主键
--将列名为id的字段设置为主键 alter table patient add primary key(id)7、(1)删除已有的主键(drop直接删除)
alter table patient drop primary key(2)删除已有的主键(列带有auto_increment属性)
--首先将自增条件去掉,再删除主键 alter table patient modify column id int alter table patient drop primary keyfirst,after只作用于add
增加的列到第一列
alter table patient add column mood VARCHAR(400) first增加的列到指定列后面
alter table patient add column mood1 VARCHAR(400) after mood增加,删除,修改列的默认值
1、修改字段默认值
alter table patient alter address set default 22、删除字段默认值
alter table patient alter address drop default3、增加新列,带默认值,在第一列
alter table patient add column mooood VARCHAR(400) default 21 first4、查看表所有字段默认值
show COLUMNS from patient mysql二、oracle 修改列名、列的数据类型
1、修改列的数据类型
alter table patient modify(mood number(5,2))2、修改列名
alter table patient rename column mood to address另:查看mysql安装路径:进入Navicat本地连接里面,新建查询:
①select @@basedir
② show variables like "%char%";
首先进入mysql
输入show variables like "%char%";
总结
以上是生活随笔为你收集整理的Alter操作(修改列名,修改列数据类型,增加列,删除列,增加列且设为主键及对默认值操作)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 网络一大抄,无耻的网站
- 下一篇: 从头开始建立神经网络翻译及扩展