mysql alter 用法,修改表,字段等信息

 

一: 修改表信息

1.修改表名 

alter table test_a rename to sys_app;

 2.修改表注释   

alter table sys_application comment '系统信息表';

二:修改字段信息

1.修改字段类型和注释

alter table sys_application  modify column app_name varchar(20) COMMENT '应用的名称';

2.修改字段类型

alter table sys_application  modify column app_name text;

3.单独修改字段注释 

目前没发现有单独修改字段注释的命令语句。

4.设置字段允许为空

alter table sys_application  modify column description varchar(255) null COMMENT '应用描述';

 5.增加一个字段,设好数据类型,且不为空,添加注释

alter table sys_application add `url` varchar(255) not null comment '应用访问地址';

 6.增加主键 

alter table t_app add aid int(5) not null ,add primary key (aid);  

7.增加自增主键

alter table t_app add aid int(5) not null auto_increment ,add primary key (aid); 

8.修改为自增主键

alter table t_app  modify column aid int(5) auto_increment ;

9.修改字段名字(要重新指定该字段的类型)

alter table t_app change name app_name varchar(20) not null;

10.删除字段

alter table t_app drop aid; 

11.在某个字段后增加字段

alter table `t_app` add column gateway_id int  not null default 0 AFTER `aid`; #(在哪个字段后面添加)  

12.调整字段顺序 

alter table t_app  change gateway_id gateway_id int not null after aid ; #(注意gateway_id出现了2次)

mysql修改表结构语句的更多相关文章

  1. mysql 修改表结构、表字段注释语句

    虽然现在有各种各样的工具可以直接对表结构进行修改,但是我还是喜欢使用语句进行修改.以下语句是对表增加字段.给字段加注释的语句 alter table orders add column isupdyq ...

  2. 程序媛计划——mysql修改表结构

    #查看表的结构 mysql> desc score; +------------+--------------+------+-----+---------+----------------+ ...

  3. MYSQL 修改表结构基本操作一览

    查看表的字段信息:desc 表名; 查看表的所有信息:show create table 表名; 添加主键约束:alter table 表名 add constraint 主键 (形如:PK_表名) ...

  4. Mysql修改表结构详解

    添加字段: alter table `user_movement_log`Add column GatewayId int not null default 0 AFTER `Regionid` (在 ...

  5. mysql 修改表结构以支持事务操作

    修改表的类型为 INNODB 的 SQL: alter table category_ ENGINE = innodb;     查看表的类型的 SQL show table status from ...

  6. SqlServer和Oracle修改表结构语句

    SQL Server:1.增加列  ALTER TABLE users ADD address varchar(30);2.删除列  ALTER TABLE users DROP COLUMN add ...

  7. mysql 修改表结构

    alter table 表名 modify column 字段名 varchar(数量); 将varchar(50)改为255 alter table 表名 modify column 字段名 var ...

  8. mysql修改表结构

    表 linksus_gov_running_trans 和 linksus_gov_running 的 is_mulsplit_id 字段需要改成 bigint(20)原:`is_mulsplit_i ...

  9. mysql 修改表结构的字段名

    alter table domains  change STATUS  status  tinyint(1)  not null;

随机推荐

  1. zabbix3.4.6之监控Oracle

    新zabbix搭建配置完后,公司所有的主机是通过自动注册完成了添加,网络设备及其Templates是从旧zabbix中Export出模板,然后Import入新zabbix系统中.一些应用的监控就需要自 ...

  2. 配置日志中显示IP

    package com.demo.conf; import ch.qos.logback.classic.pattern.ClassicConverter; import ch.qos.logback ...

  3. redis 从入门到遗忘

    Key操作 keys * *: 通配任意多个字符 ?: 通配单个字符 []: 通配括号内的某1个字符 exists key 存在返回1,不存在返回0 type key rename oldkey ne ...

  4. linux/mac下一键删除下载失败的maven jar包

    echo 正在搜索... find . -name "*lastUpdated" | xargs rm -fr echo 搜索完毕

  5. Gym - 100989F

    You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithm ...

  6. @transactional注解在什么情况下会失效,为什么。

    @transactional注解在什么情况下会失效,为什么. @Transactional的使用: @Transactional public void updateUserAndAccount(St ...

  7. 【UR #3】链式反应

    http://uoj.ac/problem/50 %炮姐 好博客 树形结构 枚举根节点的儿子是哪两个 然后列出方程: 然后有EGF的影子! 倍增? 泰勒展开可以把未知数从函数里拿出来!并且变成1次项, ...

  8. CSS解决字母不换行

    通过百度,查找解决方案 1. word-break:break-all;只对英文起作用,以字母作为换行依据2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据

  9. agc031

    T1 题意:给你一个串,求所有子序列个数,满足没有相同字符.1e5,2s. 解:考虑一个合法的子序列.其中每个字母的出现位置都有(出现次数)种选择.还可以不选,要 + 1. 然后乘起来就做完了.如果变 ...

  10. A1136. Delayed Palindrome

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...