Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
?CREATE TABLE dbo.AssociatedStopCodes
(
--source:
--A01/SQL52.SPV.Dim.AssociatedStopCode
--fields
AssociatedStopCodeID int IDENTITY(1,1) NOT NULL,
--StationID smallint null, --See RequestServices' StationID for this value
RequestServiceID int NULL, --EPRS assigned (FK), references RequestServices
StopCodeID int NULL, --EPRS assigned (FK), references StopCodes
RecordStatusID tinyint NULL, --EPRS assigned (FK), references RecordStatus
BatchLogID bigint NULL, --EPRS assigned (FK), references BatchLogs
CDWAssociatedStopCodeSysNumber int NULL, --AssociatedStopCodeSID
CDWExtractBatchNumber int NULL, --ExtractBatchID
AssociatedStopCodeIEN smallint NULL, --AssociatedStopCodeIEN
IsCommunityCareRelated bit NOT NULL, --t/l script populates this
--primary key
CONSTRAINT PK_AssociatedStopCodes PRIMARY KEY CLUSTERED
(
AssociatedStopCodeID ASC
)
)
ON DefinitionData
--when using clustered columnstore index, can't set data compression to PAGE
--using data compression, we have more than 10k recs but way less than 1 million recs
WITH (DATA_COMPRESSION = PAGE)
GO
/* Create table [SPV].[Dim].[AssociatedStopCode]
--fields
AssociatedStopCodeSID int NOT NULL, --CDWAssociatedStopCodeSysNumber
AssociatedStopCodeIEN varchar(50) NULL, --AssociatedStopCodeIEN
RequestServiceSID int NULL, --Request Services, CDWRequestServiceSysNumber
RequestServiceIEN varchar(50) NULL, --Request Services, RequestServiceIEN
Sta3n smallint NULL, --See RequestServices' StationID
StopCodeIEN varchar(50) NULL, --StopCodes, StopCodeIEN
StopCodeSID int NULL, --StopCodes, CDWStopCodeSysNumber
StopCode smallint NULL, --StopCodes, StopCodeNumber
ExtractBatchID int NULL, --CDWExtractBatchNumber
OpCode char(1) NULL, --RecordStatuses, RecordStatusID
VistaCreateDate datetime NULL, --ignore
VistaEditDate datetime NULL, --ignore
ExtractBatchID BIGINT NULL, --CDWExtractBatchNumber
BatchLogID bigint --BatchLogID
*/
--foreign keys
ALTER TABLE dbo.AssociatedStopCodes
ADD CONSTRAINT FK_AssociatedStopCodes_RequestServices
FOREIGN KEY (RequestServiceID)
REFERENCES dbo.RequestServices (RequestServiceID)
GO
ALTER TABLE dbo.AssociatedStopCodes
ADD CONSTRAINT FK_AssociatedStopCodes_StopCodes
FOREIGN KEY (StopCodeID)
REFERENCES dbo.StopCodes (StopCodeID)
GO
ALTER TABLE dbo.AssociatedStopCodes
ADD CONSTRAINT FK_AssociatedStopCodes_RecordStatuses
FOREIGN KEY (RecordStatusID)
REFERENCES dbo.RecordStatuses (RecordStatusID)
GO
ALTER TABLE dbo.AssociatedStopCodes
ADD CONSTRAINT FK_AssociatedStopCodes_BatchLogs
FOREIGN KEY (BatchLogID)
REFERENCES dbo.BatchLogs (BatchLogID)
GO
--indexes
CREATE NONCLUSTERED INDEX IX_AssociatedStopCodes_RequestServiceID ON dbo.AssociatedStopCodes
(
RequestServiceID
) WITH (
PAD_INDEX = ON, --If want to use a Fill Factor, then PAD_INDEX must = ON
FILLFACTOR = 90, --100 = max fill; set to 90 if going to insert new values incrementally; 100 if doing bulk load
SORT_IN_TEMPDB = ON, -- sorts the index in the TempDB; default = OFF
IGNORE_DUP_KEY = OFF,
STATISTICS_NORECOMPUTE = OFF,
STATISTICS_INCREMENTAL = OFF,
DROP_EXISTING = OFF,
ONLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON,
MAXDOP = 0, --degrees of parallelism, controls how many CPUs to use; 0 = default (all available), max = 64
DATA_COMPRESSION = PAGE --use page compression; default = NONE
)
ON DefinitionIndex
GO
CREATE NONCLUSTERED INDEX IX_AssociatedStopCodes_StopCodeID ON dbo.AssociatedStopCodes
(
StopCodeID
) WITH (
PAD_INDEX = ON, --If want to use a Fill Factor, then PAD_INDEX must = ON
FILLFACTOR = 90, --100 = max fill; set to 90 if going to insert new values incrementally; 100 if doing bulk load
SORT_IN_TEMPDB = ON, -- sorts the index in the TempDB; default = OFF
IGNORE_DUP_KEY = OFF,
STATISTICS_NORECOMPUTE = OFF,
STATISTICS_INCREMENTAL = OFF,
DROP_EXISTING = OFF,
ONLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON,
MAXDOP = 0, --degrees of parallelism, controls how many CPUs to use; 0 = default (all available), max = 64
DATA_COMPRESSION = PAGE --use page compression; default = NONE
)
ON DefinitionIndex
GO
--constraints
ALTER TABLE dbo.AssociatedStopCodes
ADD CONSTRAINT DF_AssociatedStopCodes_IsCommunityCareRelated
DEFAULT 0
FOR IsCommunityCareRelated
GO
--Metadata descriptions for each field
EXECUTE sp_addextendedproperty
N'MS_Description', N'Primary Key, unique to EPRS, source: Dim.AssociatedStopCode',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'AssociatedStopCodeID'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Foreign Key, unique to EPRS, relates to RequestServices table; source: RequestServiceIEN',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'RequestServiceID'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Foreign Key, unique to EPRS, relates to StopCodes table; source: StopCodeIEN',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'StopCodeID'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Foreign Key, unique to EPRS, relates to RecordStatuses table; source: opscode',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'RecordStatusID'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Foreign key, unique to EPRS, relates to Batch Logs table',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'BatchLogID'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'CDW Associated Stop Code system number; source: AssociatedStopCodeSID',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'CDWAssociatedStopCodeSysNumber'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'CDW Extract Batch number; source: ExtractBatchID',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'CDWExtractBatchNumber'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Associated Stop Code IEN; source: AssociatedStopCodeIEN',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'AssociatedStopCodeIEN'
GO
EXECUTE sp_addextendedproperty
N'MS_Description', N'Identifies if the request service is community care-related (1=true/0=false)',
N'SCHEMA', N'dbo',
N'TABLE', N'AssociatedStopCodes',
N'COLUMN', N'IsCommunityCareRelated'
GO