CREATE TABLE [dbo].[CertainTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NOT NULL,
[DateCreated] [datetime] NOT NULL,
[DateDeleted] [datetime] NULL,
[NamePower] AS (((([Name]+' (')+CONVERT([varchar],[DateCreated],(4)))+isnull('~'+CONVERT([varchar],[DateDeleted],(4)),''))+')'),
[IsDeleted] AS (CONVERT([bit],[DateDeleted])),
CONSTRAINT [PK_CertainTable] 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]
GO
ALTER TABLE [dbo].[CertainTable] ADD CONSTRAINT [DF_CertainTable_DateCreated] DEFAULT (getdate()) FOR [DateCreated]
GO
Наличие зависимых полей
deleted и
date_delete — нарушение нормальной формы. Второе оставляем, первое вычисляем. Так же вычисляем наименование с датами.
Результат:
1 TEST 2018-03-11 00:00:00.000 2018-03-12 00:00:00.000 TEST (11.03.18~12.03.18) True
2 TEST 2018-03-13 08:31:19.143 NULL TEST (13.03.18) NULL