Unique constraint on multiple columns

WE can make it with Table Query

CREATE TABLE [dbo].[user](
    [userID] [int] IDENTITY(1,1) NOT NULL,
    [fcode] [int] NULL,
    [scode] [int] NULL,
    [dcode] [int] NULL,
    [name] [nvarchar](50) NULL,
    [address] [nvarchar](50) NULL,
 CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED 
(
    [userID] ASC
),
CONSTRAINT [UQ_codes] UNIQUE NONCLUSTERED
(
    [fcode], [scode], [dcode]
)
) ON [PRIMARY]
CREATE TABLE [dbo].[user](
    [userID] [int] IDENTITY(1,1) NOT NULL,
    [fcode] [int] NULL,
    [scode] [int] NULL,
    [dcode] [int] NULL,
    [name] [nvarchar](50) NULL,
    [address] [nvarchar](50) NULL,
 CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED 
(
    [userID] ASC
),
CONSTRAINT [UQ_codes] UNIQUE NONCLUSTERED
(
    [fcode], [scode], [dcode]
)
) ON [PRIMARY]
  1. <code>
  2. CREATE TABLE [dbo].[user](
  3. [userID] [int] IDENTITY(1,1) NOT NULL,
  4. [fcode] [int] NULL,
  5. [scode] [int] NULL,
  6. [dcode] [int] NULL,
  7. [name] [nvarchar](50) NULL,
  8. [address] [nvarchar](50) NULL,
  9. CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED
  10. (
  11. [userID] ASC
  12. ),
  13. CONSTRAINT [UQ_codes] UNIQUE NONCLUSTERED
  14. (
  15. [fcode], [scode], [dcode]
  16. )
  17. ) ON [PRIMARY]
  18. </code>
<code>
CREATE TABLE [dbo].[user](
    [userID] [int] IDENTITY(1,1) NOT NULL,
    [fcode] [int] NULL,
    [scode] [int] NULL,
    [dcode] [int] NULL,
    [name] [nvarchar](50) NULL,
    [address] [nvarchar](50) NULL,
 CONSTRAINT [PK_user_1] PRIMARY KEY CLUSTERED 
(
    [userID] ASC
),
CONSTRAINT [UQ_codes] UNIQUE NONCLUSTERED
(
    [fcode], [scode], [dcode]
)
) ON [PRIMARY]
</code>
OR :

ALTER TABLE dbo.User
  ADD CONSTRAINT ucCodes UNIQUE (focde, scode, dcode)
ALTER TABLE dbo.User
  ADD CONSTRAINT ucCodes UNIQUE (focde, scode, dcode)
  1. <code>
  2. ALTER TABLE dbo.User
  3. ADD CONSTRAINT ucCodes UNIQUE (focde, scode, dcode)
  4. </code>
<code>
ALTER TABLE dbo.User
  ADD CONSTRAINT ucCodes UNIQUE (focde, scode, dcode)
</code>

Popular posts from this blog

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

C# Crop white space from around the image

The specified version string contains wildcards, which are not compatible with determinism.