MYSQL小知识 约束

 default character set utf8  设置数据库的字符集默认为utf8


collate utf8_bin:是将字符串中的每个字符用二进制数据存储,区分大小写。


collate utf8_general_cs:(case sensitive):大小写敏感


callate utf8_general_ci:(case insensitive):大小写不敏感

 

drop table if exists 表名;  --创建表

 

 创建表:

create table 表名(
字段  数据类型  not null auto_increment,
字段  数据类型  collate utf8_bin default null,
字段(时间戳) 数据类型(timestamp) not null default current_timestamp on update current_timestamp,
primary key(字段),  --增加主键
key 索引名 (字段)   --增加索引
unique key 索引名 (字段)  --增加唯一索引
constraint 外键名 foreign key(字段) reference 其他表(主键)
)engine=innodb default character=utf8 collate=utf8_bin;

为表插入数据:
insert into 表名 values(,,,...);

增加unique索引
alter table 表名 add constraint 索引名 unique(字段,,);

posted on 2018-03-26 22:30  MAOGE神  阅读(129)  评论(0编辑  收藏  举报