Inter-dependent columns

Discussion of open issues, suggestions and bugs regarding database management and development tools for SQL Server
Post Reply
dblack
Posts: 1
Joined: Wed 16 Dec 2020 17:19

Inter-dependent columns

Post by dblack » Wed 16 Dec 2020 17:28

Hi,

I have a table with the following schema:

Code: Select all

CREATE TABLE [dbo].[Content](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[IsLocked] [bit] NULL,
	[DateLocked] [datetime] NULL,
	[LockedBy] [varchar](200) NULL,
	[Region] [varchar](5) NOT NULL,
 CONSTRAINT [PK_Content] PRIMARY KEY CLUSTERED 
The values within 'IsLocked', 'DateLocked', and 'LockedBy' are all dependent on each other. Meaning that 'DateLocked' and 'LockedBy' should only contain values when 'IsLocked' has a value of '1'.

How can I set the population of the 'DateLocked' and 'LockedBy' columns to only contain data when the generated value of 'IsLocked' is equal to '1'?

Thank you for your time.
Dave


Post Reply