1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Alter操作(修改列名 修改列数据类型 增加列 删除列 增加列且设为主键及对默认值操作)

Alter操作(修改列名 修改列数据类型 增加列 删除列 增加列且设为主键及对默认值操作)

时间:2024-09-08 16:35:08

相关推荐

Alter操作(修改列名 修改列数据类型 增加列 删除列 增加列且设为主键及对默认值操作)

一、mysql (增加列,删除列,修改列;增加,删除,修改列的默认值)

增加列,删除列,修改列

1、修改列的数据类型

alter table patient modify column mood int

2、修改列名

alter table patient change mood address VARCHAR(400)

3、删除列

alter table patient drop column mood

4、增加列

alter table patient add column mood VARCHAR(400)

5、增加列为主键

alter table patient add column id BIGINT not null PRIMARY KEY auto_increment first

6、将已有的列设置为主键

--将列名为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 intalter table patient drop primary key

first,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 2

2、删除字段默认值

alter table patient alter address drop default

3、增加新列,带默认值,在第一列

alter table patient add column mooood VARCHAR(400) default 21 first

4、查看表所有字段默认值

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%";

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。