CREATE TABLE [dbo].[Serveq]
(
[PRIKEY] [int] NOT NULL IDENTITY(1, 1),
[LSPRIKEY] [int] NOT NULL,
[EqPriKey] [int] NOT NULL,
[STARTTIME] [datetime] NULL,
[ENDTIME] [datetime] NULL,
[Hours] [smallint] NULL,
[ActStartTime] [datetime] NULL,
[ActEndTime] [datetime] NULL,
[OverTimeStartTime] [datetime] NULL,
[OverTimeEndTime] [datetime] NULL,
[DispatchQuantity] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Serveq] ADD CONSTRAINT [CK_Serveq_QuantityInvalidWhenTimeSet] CHECK (([DispatchQuantity] IS NULL OR [STARTTIME] IS NULL AND [ENDTIME] IS NULL AND [ActStartTime] IS NULL AND [ActEndTime] IS NULL))
GO
ALTER TABLE [dbo].[Serveq] ADD CONSTRAINT [PK_Serveq] PRIMARY KEY CLUSTERED ([PRIKEY]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Serveq_EqPriKey] ON [dbo].[Serveq] ([EqPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ServEq_LocServ_ServiceDate] ON [dbo].[Serveq] ([EqPriKey], [PRIKEY], [LSPRIKEY]) INCLUDE ([ENDTIME], [STARTTIME]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Serveq_LSPRIKEY] ON [dbo].[Serveq] ([LSPRIKEY]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Serveq_StartTime_EqPriKey] ON [dbo].[Serveq] ([STARTTIME], [EqPriKey]) INCLUDE ([ENDTIME]) ON [PRIMARY]
GO
CREATE STATISTICS [STAT_ServEq_LocServ_2] ON [dbo].[Serveq] ([EqPriKey], [LSPRIKEY])
GO
CREATE STATISTICS [STAT_ServEq_LocServ_1] ON [dbo].[Serveq] ([LSPRIKEY], [PRIKEY], [EqPriKey])
GO
ALTER TABLE [dbo].[Serveq] ADD CONSTRAINT [FK_Serveq_EQUIP] FOREIGN KEY ([EqPriKey]) REFERENCES [dbo].[Equip] ([PriKey])
GO
ALTER TABLE [dbo].[Serveq] ADD CONSTRAINT [FK_Serveq_LOCSERV] FOREIGN KEY ([LSPRIKEY]) REFERENCES [dbo].[LocServ] ([PriKey])
GO
GRANT SELECT ON [dbo].[Serveq] TO [MssExec]
GRANT INSERT ON [dbo].[Serveq] TO [MssExec]
GRANT DELETE ON [dbo].[Serveq] TO [MssExec]
GRANT UPDATE ON [dbo].[Serveq] TO [MssExec]
GO