CREATE TABLE [dbo].[PrintJobQueue] (
    [IdxPrintJob] INT            IDENTITY (1, 1) NOT NULL,
    [TipoCart]    NVARCHAR (250) NOT NULL,
    [UDC]         NVARCHAR (50)  NOT NULL,
    [prtName]     NVARCHAR (500) NOT NULL,
    [dtStart]     DATETIME       NOT NULL,
    [dtEnd]       DATETIME       NULL,
    [stato]       INT            CONSTRAINT [DF_printJobQueue_stato] DEFAULT ((0)) NOT NULL,
    [dtLastTry]   DATETIME       NULL,
    CONSTRAINT [PK_printJobQueue] PRIMARY KEY CLUSTERED ([IdxPrintJob] ASC) WITH (FILLFACTOR = 95)
);


GO
CREATE NONCLUSTERED INDEX [i_awaitingPrint]
    ON [dbo].[PrintJobQueue]([stato] ASC) WHERE ([stato]=(0)) WITH (FILLFACTOR = 95);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'chiave con ordinamento FIFO', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'IdxPrintJob';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'tipo di cartellino', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'TipoCart';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'cod UDC da stampare', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'UDC';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'printer name (nome completo stampante)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'prtName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'dataora richiesta', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'dtStart';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'data/ora evento stampa/annullamento', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'dtEnd';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'stato: 0=wait, 1=fatto, -1=annullato', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'stato';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = 'data/ora ultimo tentativo di stampa (x check se zombie process)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'PrintJobQueue', @level2type = N'COLUMN', @level2name = N'dtLastTry';

