I have created a custom table which was created using the following SQL:
IF Not Exists(select * from sys.tables where name = 'CustAIEverestData')
CREATE TABLE [dbo].[CustAIEverestData](
[CompanyID] [int] NOT NULL,
[EverestDataID] [int] IDENTITY(1,1) NOT NULL,
[CustCode] [char] (20) NOT NULL,
[CustName] [char] (50),
[EverestOrderDate] [datetime] NOT NULL,
[EverestOrderNo] [char] (20) UNIQUE,
[EverestSalesRep] [char] (10) NOT NULL,
[EverestTerms] [char] (20) NOT NULL,
[EverestTaxable] [decimal] (18,6) NOT NULL,
[EverestTaxAmount] [decimal] (18,6) NOT NULL,
[EverestInvoiceAmount] [decimal] (18,6) NOT NULL,
[EverestFOB] [char] (20),
[EverestDeliveryMethod] [char] (20),
[EverestWeight] [decimal] (18,6) NOT NULL,
[EverestTracking] [char] (50),
[CreatedDateTime] [datetime] NOT NULL,
[CreatedByID] [uniqueidentifier] NOT NULL,
[CreatedByScreenID] [char](8) NOT NULL,
[LastModifiedDateTime] [datetime] NOT NULL,
[LastModifiedByID] [uniqueidentifier] NOT NULL,
[LastModifiedByScreenID] [char](8) NOT NULL,
[tstamp] [timestamp] NOT NULL,
[NoteID] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_CustAIEverestData] PRIMARY KEY CLUSTERED
(
[CompanyID] ASC,
[EverestDataID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [primary]
) ON [primary]
GO
All seems fine until I tried to do a full snapshot on the tenant. I am getting an error saying:
PX.Data.PXException: An error occurred while importing data into the 'CustAIEverestData' table. ---> System.Exception: Violation of UNIQUE KEY constraint 'UQ__CustAIEv__385E4D6441B3D86A'. Cannot insert duplicate key in object 'dbo.CustAIEverestData'. The duplicate key value is (4982760 ).
and the snapshot inevitably fails.
Is the problem in the way I defined the fields in the SQL? The only unique field is EverestOrderNo so I suspect I should be using a different method of making sure duplicates cannot be imported into the same tenant as the same order no could exist in different tenants (and presumably needs to for the snapshot to work). Does anyone know how I go about getting past this issue? How should I define the field so that duplicates cannot accidentally be imported into the same tenant but snapshots work correctly? Or am I misunderstanding the error and the cause?
Thanks,
Phil