SQL语句

    DLL        数据定义语言

        create,drop

    DML     数据操纵语言

        insert,delete,select,update

    DCL        数据控制语言

        grant,revoke

使用ALTER TABLE修改表结构

(1)修改表名

ALTER TABLE <表名> RENAME <新表名>

mysql> alter table game_account rename account;
Query OK, 0 rows affected (0.05 sec)

(2)修改表的搜索引擎

mysql> alter table account engine=MyISAM;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

查看表的信息

mysql> show create table account\G;
*************************** 1. row ***************************
       Table: account
Create Table: CREATE TABLE `account` (
  `game_name` char(15) NOT NULL,
  `game_password` char(25) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
ERROR: 
No query specified

(3)添加字段

ALTER TABLE <表名> ADD <字段名称> <字段定义>

后面添加:

mysql> alter table account add game_sex enum("M","F") not null;

前面添加:

mysql> alter table account add game_address varchar(20) not null default "huabei" first;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

中间添加:

mysql> alter table account add game_money int after game_name;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

(4)删除字段

ALTER TABLE <表名> drop <字段名称>

mysql> alter table account drop game_wei;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

(5)修改字段名称及字段定义

ALTER TABLE <表名> CHANGE <旧字段> <新字段名称> <字段定义>

mysql> alter table account change game_zhang wei char(25) not null;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> alter table account change wei wei varchar(60)  ;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

(6)修改字段定义

ALTER TABLE <表名> MODIFY <字段名称> <字段定义>

mysql> alter table account modify wei int ;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> alter table account modify wei int  not null ;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

MySQL使用alter修改表的结构的更多相关文章

  1. alter修改表

    alter修改表的基础语句,语法如下: ALTER TABLE table_name ADD column_name|MODIFY column_name| DROP COLUMN column_na ...

  2. 查看mysql字符集及修改表结构--表字符集,字段字符集

    MySQL 乱码的根源是的 MySQL 字符集设置不当的问题,本文汇总了有关查看 MySQL 字符集的命令.包括查看 MySQL 数据库服务器字符集.查看 MySQL 数据库字符集,以及数据表和字段的 ...

  3. 查看mysql字符集及修改表结构

    MySQL 乱码的根源是的 MySQL 字符集设置不当的问题,本文汇总了有关查看 MySQL 字符集的命令.包括查看 MySQL 数据库服务器字符集.查看 MySQL 数据库字符集,以及数据表和字段的 ...

  4. mysql中如何修改表的名字?修改表名?

    需求描述: 今天在进行mysql表的历史数据迁移,需要将某张表进行备份,修改表的名字,在此记录下操作过程. 操作过程: mysql> create table ts01 like ti_o_sm ...

  5. MySQL查看和修改表的存储引擎(转载+加点东西)

    1 查看系统支持的存储引擎 show engines; 2 查看表使用的存储引擎 两种方法: a.show table status from YOUR_DB_NAME where name='YOU ...

  6. MySQL查看和修改表的存储引擎

    1 查看系统支持的存储引擎 show engines; 2 查看表使用的存储引擎 两种方法: a.show table status from db_name where name='table_na ...

  7. 通过sql语句修改表的结构

    1.修改表的列名 oracle: ALTER TABLE 表名 RENAME COLUMN 列名 TO 新列名sqlserver:exec sp_rename '[表名].[列名]','[表名].[新 ...

  8. MySQL中的修改表操作

    一.增加表的列 语法:alter table 表名 add(           增加列定义          ); 实例: #增加列 alter table text add( text_num ) ...

  9. mysql基本的修改表的命令

    修改表相关的命令 1.添加列表 alter table 表名 add 列名 类型; 2.删除某一列 alter table userinfo drop column 列名; 3.修改列的类型 alte ...

随机推荐

  1. angularjs 运行时报错ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/t

    解决方法: 在package.json文件里面 修改 "rxjs": "^6.0.0" 为 "rxjs": "6.0.0" ...

  2. 【oracle】ORA-12638 : 身份证明检索失败

    sqlnet.ora 1.删了 2.#注释了 背后缘由:待写

  3. CSP考前复习

    前言 因为loceaner太菜了,他什么东西都不会 所以他打算学一个东西就记录一下 不过因为他很菜,所以他不会写原理-- 而且,他希望在2019CSP之前不会断更 就酱紫,就是写给他自己的--因为他太 ...

  4. Python爬虫练习

    例一:爬取信息关于'gbk' codec can't encode character '\xa0' in position 6: illegal 错误提示: #初始化class 得到对象 draw= ...

  5. linux shell脚本中的延时

    linux shell脚本中的延时 还是使用 sleep 或usleep函数. 详细如下:     .sleep : 默认为秒. sleep 1s 表示延迟一秒   sleep 1m 表示延迟一分钟 ...

  6. Visual Studio 调试系列11 远程调试

    系列目录     [已更新最新开发文章,点击查看详细] 你可以调试已部署在另一台计算机的 Visual Studio 应用程序. 要进行此操作,可使用 Visual Studio 远程调试器. 01 ...

  7. zipfile

    zipfile是一个用于处理zip压缩格式的文件的模块, 主要会用到它的ZipFile类 import zipfile zipfile.is_zipfile('myzip.zip')) # 判断一个文 ...

  8. 动手学深度学习7-从零开始完成softmax分类

    获取和读取数据 初始化模型参数 实现softmax运算 定义模型 定义损失函数 计算分类准确率 训练模型 小结 import torch import torchvision import numpy ...

  9. 第五节:EF Core中的三类事务(SaveChanges、DbContextTransaction、TransactionScope)

    一. 说明 EF版本的事务介绍详见: 第七节: EF的三种事务的应用场景和各自注意的问题(SaveChanges.DBContextTransaction.TransactionScope). 本节主 ...

  10. 34 个今年11月最受欢迎的 JavaScript 库

    作者:Iren Korkishko 译者:前端小智 来源:dev 点赞再看,养成习惯 本文 GitHub:github.com/qq449245884… 上已经收录,更多往期高赞文章的分类,也整理了很 ...