5.5数据库上课笔记

索引是查询时才有用,索引必须独立存在。

索引的类型,查看索引,创建索引,索引底层长什么样子

1.主键也叫主索引

create table test2(id int primary key);

2.replace into demo(id,name,age) values(1,'王五',24);

select * from demo;

创建主键(索引)的方法1:create table test2(id int primary key);

创建主键(索引)的方法2:create table test3(id int, primary key(id));

创建普通索引:基本要求属性值是可以重复的只要是列就行
create index idx_name on demo(name);

 show index from demo;

 create table test4(id int,name varchar(10),
    -> primary key(id),
    -> unique(name)
    -> );

  show index from demo;

 show index from test4;

 insert into test4 values(1,'tom');

create table test5(id int,name varchar(10),
    -> constraint mypri primary key(id),
    -> constraint myuiq unique(name)
    -> );

show index from test5;

  alter table test5 drop primary key;

show index from test5;

 alter table test5 drop index myuiq;

 show index from test5;

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值