Functional Indexes for Microsoft SQL Server
The following example shows how the key fields are concatenated:
USE FS840U70
go
SET IMPLICIT_TRANSACTIONS ON
go
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME =
'PS_QE_ALTER_NEW') DROP TABLE PS_QE_ALTER_NEW
go
CREATE TABLE PS_QE_ALTER_NEW (QE_ALTER_FLD1 NCHAR(1) NOT NULL,
QE_ALTER_FLD2 NCHAR(1) NOT NULL,
QE_ALTER_FLD3 NCHAR(1) NOT NULL,
QE_ALTER_FLD4 NCHAR(10) NOT NULL,
QE_ALTER_FLD5 NCHAR(20) NOT NULL,
QE_ALTER_FLD6 NCHAR(11) NOT NULL,
QE_ALTER_FLD7 NCHAR(1) NOT NULL,
QE_ALTER_FLD8 NCHAR(1) NOT NULL,
QEPC_AGE SMALLINT NOT NULL,
QEPC_FILE_NUM DECIMAL(6, 2) NOT NULL,
QE_BEGIN_DT PSDATE NULL,
QE_BIRTHDATE PSDATE NULL,
QE_31DIGFLD9 DECIMAL(31, 8) NOT NULL,
QE_ANNUAL_PCT DECIMAL(3, 1) NOT NULL,
QE_MS_DTTM1 PSDATETIME NULL,
QE_MS_DTTM2 PSDATETIME NULL,
QE_ALTER_TIMEA PSTIME NULL,
QE_ALTER_TIMEB PSTIME NULL,
MSSCONCATCOL AS QE_ALTER_FLD1 + QE_ALTER_FLD2 + QE_ALTER_FLD3 +
QE_ALTER_FLD4 + QE_ALTER_FLD5 + QE_ALTER_FLD6 + QE_ALTER_FLD7 +
QE_ALTER_FLD8 + CONVERT(NCHAR,QEPC_AGE) + CONVERT(NCHAR
,QEPC_FILE_NUM) + CONVERT(NCHAR(16),QE_BEGIN_DT, 109) +
CONVERT(NCHAR(16),QE_BIRTHDATE, 109) + CONVERT(NCHAR,QE_31DIGFLD9) +
CONVERT(NCHAR,QE_ANNUAL_PCT) + CONVERT(NCHAR(16),QE_MS_DTTM1, 109) +
CONVERT(NCHAR(16),QE_MS_DTTM2, 109) + CONVERT(NCHAR(16)
,QE_ALTER_TIMEA, 109))
go
COMMIT
go
SET ARITHABORT ON
go
CREATE UNIQUE CLUSTERED INDEX PS_QE_ALTER_NEW ON PS_QE_ALTER_NEW
(MSSCONCATCOL)
go
CREATE NONCLUSTERED INDEX PSWQE_ALTER_NEW ON PS_QE_ALTER_NEW
(QE_ALTER_FLD1,
QE_ALTER_FLD2,
QE_ALTER_FLD3,
QE_ALTER_FLD4,
QE_ALTER_FLD5,
QE_ALTER_FLD6,
QE_ALTER_FLD7,
QE_ALTER_FLD8,
QEPC_AGE,
QEPC_FILE_NUM,
QE_BEGIN_DT,
QE_BIRTHDATE,
QE_31DIGFLD9,
QE_ANNUAL_PCT,
QE_MS_DTTM1,
QE_MS_DTTM2)
go
COMMIT
Go