CREATE UNIQUE NONCLUSTERED INDEX <indexName>
ON <tableName> (AnswerID, PollID, CreatedBy)
WHERE CreatedBy IS NOT NULL;
如果您说“非空”,那么可以使用以下代码:
CREATE UNIQUE NONCLUSTERED INDEX <indexName>
ON <tableName> (AnswerID, PollID, CreatedBy)
WHERE CreatedBy IS NOT NULL
AND CreatedBy <> N'';
CREATE VIEW dbo.vw_Tablename
WITH SCHEMABINDING AS
SELECT AnswerID, PollID, CreatedBy
FROM dbo.Tablename
WHERE CreatedBy IS NOT NULL;
GO
CREATE UNIQUE CLUSTERED INDEX UIX_vw_Tablename
ON dbo.vw_Tablename(AnswerID, PollID, CreatedBy)