简体   繁体   English

Visual Studio SQL Designer中的唯一约束

[英]Unique Constraint in Visual Studio SQL Designer

I was looking at ways to make a newly added column a Unique but not primary column. 我正在研究使新添加的列成为唯一列而不是主列的方法。 I had a look at this W3School link . 我看了一下这个W3School链接 But Instead of following their approach I simply changed my table in the Visual Studio designer as. 但是,与其遵循他们的方法,我只是在Visual Studio设计器中将表更改为。

CREATE TABLE [dbo].[Userpro] (
    [Id]                INT             NOT NULL IDENTITY,
    [Name]              NVARCHAR (50)   NULL,
    [Postcode]          NVARCHAR (4)    NULL,
    [Gender]            INT             NULL,
    [Blog]              NVARCHAR (MAX)  NULL,
    [FeedBack]          NVARCHAR (MAX)  NULL,
    [Username]          NVARCHAR (50)   NOT NULL Unique,
PRIMARY KEY CLUSTERED ([Id] ASC)
);

Notice that I simply added "Unique" [Username] NVARCHAR (50) NOT NULL Unique . 请注意,我只是添加了“ Unique” [Username] NVARCHAR (50) NOT NULL Unique I am unsure if this has the same effect or should I go back and just use the script in the link. 我不确定这是否具有相同的效果,还是应该返回并仅使用链接中的脚本。

That is perfect. 太好了

Adding UNIQUE will have the effect you describe. 添加UNIQUE将具有您描述的效果。 It is also explained in the link you provide. 您提供的链接中也对此进行了说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM