主键和唯一约束unique之间的区别

要用无实际意义的做主键

不要用业务逻辑做主键,如果要改,关联的外键也需要改
查询效率低
要用一个没有实际意义的编号做主键 stu_id


create table student4
(

stu_id int primary key identity(1,1),--自增
stu_name nvarchar(50) unique not null,
stu_email nvarchar(50) not null,
stu_address nvarchar(50)

)

drop table student4; --删除student4

posted @ 2026-04-21 00:58  菜鸟的奋斗军  阅读(9)  评论(0)    收藏  举报