源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

MySQL学习笔记之创建、删除、修改表的方法

  • 时间:2021-02-23 19:25 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:MySQL学习笔记之创建、删除、修改表的方法
本文实例讲述了MySQL学习笔记之创建、删除、修改表的方法。分享给大家供大家参考,具体如下: [b]创建表:[/b]
create table users(
  id int,
  name varchar(64),
  sex bit(1),
  birthday date,
  Entry_date date,
  job varchar(32),
  salary float,
  resume text
);

[b]1 添加列:[/b] alter table 表名 add 列名 数据类型
alter table users add image blob;

[b]2 修改列:[/b] alter table 表名 modify 列名 新的数据类型(数据长度大小)
alter table users modify sex char(2);

[b]3 删除列:[/b] alter table 表名 drop 列名
alter table users drop image;

[b]4 修改表名:[/b] rename table 表名 to  新表名
rename table users to user;

[b]5 修改表的字符集:[/b] alter table 表名 character set 字符集
alter table user character set gbk

[b]6 修改列名字:[/b] alter table 表名 change column 原列名 新列名 类型
alter table users change column sex sexy varchar(2);

[b]7 查看表结构:[/b]
mysql> describe users;
+------------+-------------+------+-----+---------+-------+
| Field   | Type    | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id     | int(11)   | YES |   | NULL  |    |
| name    | varchar(64) | YES |   | NULL  |    |
| sex    | bit(1)   | YES |   | NULL  |    |
| birthday  | date    | YES |   | NULL  |    |
| Entry_date | date    | YES |   | NULL  |    |
| job    | varchar(32) | YES |   | NULL  |    |
| salary   | float    | YES |   | NULL  |    |
| resume   | text    | YES |   | NULL  |    |

[b]8 查看表创建结构:[/b]
mysql> show create table users;

[b]9 删除表:[/b]
mysql> drop table test9;

更多关于MySQL相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/621.htm]MySQL索引操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/594.htm]MySQL日志操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/441.htm]MySQL事务操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/563.htm]MySQL存储过程技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/568.htm]MySQL数据库锁相关技巧汇总[/url]》及《[url=http://www.1sucai.cn/Special/606.htm]MySQL常用函数大汇总[/url]》 希望本文所述对大家MySQL数据库计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部