Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 650 characters in body
Source Link

I want to create this table with the following constrains, is it possible to do with SQL Server Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]

Update: My table create query is the following:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[User](
    [Id] [int] IDENTITY(1,1) NOT NULL, 
    [ProductId] [int] NULL,
    [CompanyId] [int] NULL,
    [Username] [nvarchar](max) NOT NULL,
    [Identifier] [nvarchar](max) NULL,
    [DeletedAt] [datetime2](7) NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

I want to create this table with the following constrains, is it possible to do with SQL Server Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]

I want to create this table with the following constrains, is it possible to do with SQL Server Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]

Update: My table create query is the following:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[User](
    [Id] [int] IDENTITY(1,1) NOT NULL, 
    [ProductId] [int] NULL,
    [CompanyId] [int] NULL,
    [Username] [nvarchar](max) NOT NULL,
    [Identifier] [nvarchar](max) NULL,
    [DeletedAt] [datetime2](7) NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
added 5 characters in body; edited title
Source Link
The Impaler
  • 49.3k
  • 10
  • 50
  • 90

Uniqe Unique constraint on another column if not null

I want to create this table with the following constrains, is it possible to do with MSSQLSQL Server Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]

Uniqe constraint on another column if not null

I want to create this table with the following constrains, is it possible to do with MSSQL Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]

Unique constraint on another column if not null

I want to create this table with the following constrains, is it possible to do with SQL Server Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]
Source Link

Uniqe constraint on another column if not null

I want to create this table with the following constrains, is it possible to do with MSSQL Management Studio?

  • Id
  • ProductId [Nullable column]
  • CompanyId [Nullable column]
  • Username [unique for every productId - IF DeletedAt is not NULL]
  • Identifier [Nullable column] [unique for every companyId - IF DeletedAt is not NULL]
  • DeletedAt [Nullable column]