CREATE TABLE [dbo].[ATDocumentCabinetDef] (
    [FieldID]          INT              NOT NULL IDENTITY (1, 1),
    [CabinetID]        INT              NOT NULL,
    [FieldName]        NVARCHAR (255)   NOT NULL,
    [FieldDescription] NVARCHAR (255)   NULL,
    [FieldDataType]    NVARCHAR (255)   NOT NULL,
    [FieldDataTypeId]  INT              NULL,
    [FieldSize]        INT              NOT NULL,
    [DefaultValue]     NVARCHAR (255)   NULL,
    [ObjectId]         UNIQUEIDENTIFIER NOT NULL DEFAULT(NEWID()),
    [Display]          BIT              NOT NULL DEFAULT(1),
    CONSTRAINT [PK_ATDocumentCabinetDef] PRIMARY KEY ([FieldID] ASC),
    CONSTRAINT [UK_ATDocumentCabinetDef_FieldName_CabinetId] UNIQUE (CabinetID, [FieldName] ASC),
    CONSTRAINT [UK_ATDocumentCabinetDef_ObjectId] UNIQUE ([ObjectId] ASC),
    CONSTRAINT [FK_ATDocumentCabinetDef_ATDocumentCabinet] FOREIGN KEY ([CabinetID]) REFERENCES [dbo].[ATDocumentCabinet] ([CabinetID]),
    CONSTRAINT [FK_ATDocumentCabinetDef_ATDocumentCabinetFiledType] FOREIGN KEY ([FieldDataTypeId]) REFERENCES [dbo].[ATDocumentCabinetFiledType] ([Id])
);


GO
CREATE NONCLUSTERED INDEX [ATDocumentCabinetDef_IX_FieldID]
    ON [dbo].[ATDocumentCabinetDef]([FieldID] ASC);

