﻿CREATE TABLE [dbo].[DiesDet] (
    [CodDies]      NVARCHAR (50)  NOT NULL,
    [HoleNum]      INT            NOT NULL,
    [CodItem]      NVARCHAR (50)  NOT NULL,
    [CodDiesGroup] NVARCHAR (50)  NOT NULL,
    [Price]        DECIMAL (9, 3) CONSTRAINT [DF_DiesDet_Price] DEFAULT ((0)) NOT NULL,
    [TestCost]     DECIMAL (9, 3) CONSTRAINT [DF_DiesDet_Price1] DEFAULT ((0)) NOT NULL,
    [ExpLife]      DECIMAL (9, 2) NOT NULL,
    [ActLife]      DECIMAL (9, 2) NOT NULL,
    [Active]       INT            NOT NULL,
    CONSTRAINT [PK_DiesDet] PRIMARY KEY CLUSTERED ([CodDies] ASC),
    CONSTRAINT [FK_DiesDet_DiesGroupDet] FOREIGN KEY ([CodDiesGroup]) REFERENCES [dbo].[DiesGroupDet] ([CodDiesGroup]) ON UPDATE CASCADE,
    CONSTRAINT [FK_DiesDet_ItemDet] FOREIGN KEY ([CodItem]) REFERENCES [dbo].[ItemDet] ([CodItem]) ON UPDATE CASCADE
);




GO
CREATE NONCLUSTERED INDEX [i_DiesDet_CodItem_CodDiesGroup_Active]
    ON [dbo].[DiesDet]([CodItem] ASC, [CodDiesGroup] ASC, [Active] ASC)
    INCLUDE([Price], [ExpLife], [ActLife]);


GO
CREATE NONCLUSTERED INDEX [i_DiesDet_Active_CodDiesGroup_Filtered]
    ON [dbo].[DiesDet]([CodDiesGroup] ASC, [CodItem] ASC)
    INCLUDE([ActLife], [Price], [ExpLife]) WHERE ([Active]=(0));




GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'codice matrice', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'CodDies';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'codice articolo', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'CodItem';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'codice CLASSE matrice, es tipo + diametro; nota: massima numerosità pari a numero articoli, minima numerosità 1', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'CodDiesGroup';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'prezzo di acquisto', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'Price';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'costo di prove e correzioni', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'TestCost';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Durata attesa in kg PREVISTA', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'ExpLife';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Durata attuale (delle rottamate, media) in kg', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'ActLife';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Stato: 1 = disponibile, 0 = rottamata', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'DiesDet', @level2type = N'COLUMN', @level2name = N'Active';

