有个小需求,在数据库中存在的列中添加一个唯一约束。记录下来,留做备忘。对ExternalConfirmNo字段约束。
ALTER TABLE [ChannelExternalReservations] WITH NOCHECK ADD
CONSTRAINT [PK_ChannelExternalReservations_ExternalConfirmNo] unique
(
[ExternalConfirmNo]
)
GO
CONSTRAINT [PK_ChannelExternalReservations_ExternalConfirmNo] unique
(
[ExternalConfirmNo]
)
GO
同时加上删除约束的sql。
alter table [ChannelExternalReservations]
drop constraint [PK_ChannelExternalReservations_ExternalConfirmNo]
drop constraint [PK_ChannelExternalReservations_ExternalConfirmNo]