Alter操作(修改列名,修改列数据类型,增加列,删除列,增加列且设为主键及对默认值操作) 您所在的位置:网站首页 mysql如何修改数据类型和内容 Alter操作(修改列名,修改列数据类型,增加列,删除列,增加列且设为主键及对默认值操作)

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

2023-12-17 10:19| 来源: 网络整理| 查看: 265

一、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 int alter 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%";



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有