sql 中unique与distinct 的区别

unique 和 distinct 都是去重的意思,但他们所用的语句不同

1:unique 可以用于在创建表时或者在修改表的结构时使用

例如:

create table test(sno int not null unique);

或者 alter table test alter unique(sname);

2:distinct则是用于对select 语句使用

例如: select distinct depart from test


总之,这两个是可以去重的,但使用的时候要灵活运用


猜你喜欢

转载自blog.csdn.net/qq_41682681/article/details/80780657