【摘要】 数据库mysq
– 【】里面的内容可以加可以不加
1
数据库的命令
create database 命明 (创建数据库)show databases (查看所有数据库)show create databases 自己的数据库(查看单个数据库)alter database 自己的数据库 default character set (gbk)collate gbk_b…
数据库mysq
- 【】里面的内容可以加可以不加
数据库的命令
- create database 命明 (创建数据库)
- show databases (查看所有数据库)
- show create databases 自己的数据库(查看单个数据库)
- alter database 自己的数据库 default character set (gbk)collate gbk_bin(修改数据库编码格式)
- drop databases 数据库名字 (删除数据库)
表的命令
-
use 数据库名 (打开数据库)
-
create table 表名(字段名1~n 数据类型 【完整性约束条件】)(创建表)。varchar () (字符长度代码)
-
desc 表名 (查看表)
-
show create table 表名 (查看数据库里面的表 不用打开数据库)
-
alter table 旧表名rename 【to】 新表面 (修改表名)
-
alter table 表名 CHANGE 字段名 新字段名 int; //修改一个字段的名称,此时一定要重新
-
alter table 表名 MODIFY 字段名 数据类型; //修改一个字段的类型
-
alter table 表名 add 字段名 int(4);
//增加字段 -
alter table 表名 modify 字段名1 字段类型 FIRST|AFTER; first(前面) aftep(后面)
//修改字段位置 -
alter table 表名 drop 字段名;
//删除字段 -
drop table 表名
//删除表 -
create table 表名 ( 字段1 字段类型 primary key,字段2 字段类型, 字段3字段类型);
//创建表+字段附加主键。 primary key(主键) -
alter table 表名 drop primary key;
//删除主键 -
alter table 表名 modify 字段1 字段类型 primary key;
//创建主键 -
primary key(字段1,字段2)
//创建 新表 +主键与复合主键
- constraint 外键名 foreign key (从表的外键字段名) references 主表名(主表的主键字段名)
//创建表时添加外键约束 - alter table 从表名 add constraint 外键名 foreign key (从表的外键字段名)references 主键名(主表的主键字段名)
//为已存在的添加外键约束 - alter table 从表名 drop foeeign key 外建名;
//删除外键约束 - alter table 表名 modify 字段名 字段类型 not null;
//给已存在的表添加非空类型- alter table 表名 modify 字段名 字段类型;
//删除非空类型
- alter table 表名 modify 字段名 字段类型;
- alter table 表名 modify 字段名 字段类型 unique;
//添加唯一约束 - alter table 表名 drop index 字段名 ;
//删除唯一约束 - create table 表名 (字段名 字段类型 primary key,字段名 字段类型 unique, 字段名 字段类型 not null)
//创建表+唯一约束+非空约束 - alter table 表名 add 字段名 字段类型 default ‘内容’;
//增加一个字段+约束默认值- alter table 表名 modify 字段名 字段类型 ;
//删除默认值
- alter table 表名 modify 字段名 字段类型 ;
- alter table 表名 modify 字段名 字段类型auto_increment;
//添加自动添加功能 - alter table 表名 modify 字段名字段类型;
//删除 自动添加功能
文章来源: blog.csdn.net,作者:放纵.,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_42247868/article/details/115747527