---增加主键
alter table tb add constraint primary ket(t);
alter table tb add constraint pk primary key(t);
--删除主键
alter table tb drop primary key;
---建立外键
alter table tb add constraint fk foreign key(t1) references tb(t1) on delete set null on update cascade;
--删除外键
alter table tb drop foregin key pk;
索引:功能和书的检索目录相像,占用硬盘空间,降低了插入和修改的速度
PS:一般主键,唯一约束自带索引
----建立索引
create index ii on teacher (tname tetnamesc);
--删除索引
drop index ii on teacher;
alter table teacher drop index tname;
--增加索引
alter table teacher add index (tname asc);
ps:ase 索引中升序,可不带;desc降序
create table aaa(
tid INT UNSIGNED NOT NULL AUTO-INCREATE,
tname VARCHAR(30),
KEY(tname DESC),
PRIMARY KEY(tid)
)ENGINE=MYISAM
网友评论