【MySQL基础】表的基本操作
来源:互联网 发布:template.js if else 编辑:程序博客网 时间:2024/06/07 08:11
1.创建表
例:创建一张名为employee的表
2.查看表结构
(1)显示表的结构
例:查看employee的表结构
(2)查看表的建表语句
例:查看表employee的建表语句
(3)查看数据库中的所有表
例:查看数据库dream中的所有表
3.修改表的结构
(1)增加列
例:给表employee增加一列,表名为image,数据类型为blob
(2)修改列
例:修改表employee中salary列的数据类型为float,并把salary列置顶
(3)删除列
例:删除表employee中的gender列
(4)修改字符集
例:将表employee的字符集修改为GBK
(5)修改列名
例:将表employee中列name修改为username
(6)更改表名
例:将表employee更改为 user
方式一:
方式二:
(7)删除表
例:删除表student
4.表的约束
(1)主键约束
*单字段
id int primary key,
*多字段
primary key (id int, name varchar(20)),
(2)非空约束
id int not null,
(3)唯一约束
name varchar(20) unique,
(4)默认约束
salary float default 1000,
(5)字段值自动增加
id int auto_increment,
5.创建索引
(1)创建新索引(创建表时创建索引)
*创建普通索引
index (id),
*创建唯一索引
unique index unique_id (id asc),
*创建全文索引
fulltext index fulltext_name (name),
注:engine=MyISAM
*创建单列索引
index single_name (name(20)),
*创建多列索引
index multi(id, name(20)),
*创建空间索引
spatial index sp (space),
(2)使用create index语句在已经存在的表上创建索引
*创建普通索引
create index index_id on employee (id);
*创建唯一索引
create unique index unique_id on employee (id);
*创建全文索引
create fulltext index fulltext_name on employee (name);
*创建单列索引
create index single_id on employee (id);
*创建多列索引
create index multi on employee (id,name(20));
*创建空间索引
create spatial index spatidx on employee (space);
(3)使用alter table 语句在已存在的表上创建索引
*创建普通索引
alter table employee add index idx(id);
*创建唯一索引
alter table employee add unique uniqueidx(id);
*创建全文索引
alter table employee add fulltext index fulltextidx(id);
*创建单列索引
alter table employee add single singleidx(id);
*创建多列索引
alter table employee add multi multidx(id,name(20));
*创建空间索引
alter table employee add spatial spatidx(space);
6.删除索引
(1)使用alter table 语句删除索引
alter table employee drop index fulltextidx;
(2)使用index删除索引
drop index spatidx on employee;
本人才疏学浅,如有错误,请指出
谢谢!
- 【MySQL基础】表的基本操作
- Mysql基础—对数据库和表的基本操作
- MySQL基础2---数据库的基本操作
- MySQL基础-数据库基本操作
- mysql(基础篇)之MySQL基本操作
- 【MySQL基础】库的基本操作与数据类型
- mysql基础(2)——数据表的基本操作
- MySQL的基本操作
- Mysql的基本操作
- MySQL的基本操作
- MySQL的基本操作
- mysql的基本操作
- MySql的基本操作
- MySql的基本操作
- mysql 的基本操作
- mysql的基本操作
- MySQL的基本操作
- MySQL的基本操作
- Linux学习笔记——进程间的通信-文件和文件锁
- Git-Error-Permission denied (publickey).
- android的背光调节
- 2.Springboot 之 Helloworld
- Android-自动化测试之MonkeyRunner教程(详细)
- 【MySQL基础】表的基本操作
- hbase使用Phoenix
- Android保存本地图片到SQLite
- Hibernate初探之单表映射笔记(2)
- jqgrid获取Column属性
- 求字符串的最长重复子串——Java实现
- DeepLearning——学习
- (VirtualBox)Linux系统上添加一块新磁盘
- Vue入门系列之Vue实例详解与生命周期(转载)