1.主键
①设置主键
alter table users
add primary key(userID);
create table user1(userID varchar(10) primary key,userName varchar(10));
create table user2(userID varchar(10),userName varchar(10),primary key(userID,userName));
②删除主键
alter table user2
drop primary key;
2.select运算
select 1+2;
3.char和varchar的区别
①
char类型的长度是固定的
varchar类型的长度是可变的
②
char类型每次修改的数据长度相同,效率更高
varchar类型每次修改的数据长度不同,效率更低
③
char类型存储的时候是初始预计字符串再加上一个记录字符串长度的字节,占用空间较大
varchar类型存储的时候是实际字符串再加上一个记录字符串长度的字节,占用空间较小
4.index索引
①创建索引
create index id on user1(userID);
alter table user1
add index id(userID);
create table user3(userID varchar(10),userName varchar(10),index id(userID));
②查看唯一性约束
show keys from user3;
③删除索引
drop index id on user3;