美文网首页百人计划
mysql(5)索引的使用

mysql(5)索引的使用

作者: Martian_116b | 来源:发表于2017-07-11 22:55 被阅读0次

    ---增加主键

    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

    相关文章

      网友评论

        本文标题:mysql(5)索引的使用

        本文链接:https://www.haomeiwen.com/subject/ostvhxtx.html