[code="sql"]CREATE TABLE [dbo].[t_Transactions]( [ID] [int] IDENTITY(1,1) NOT NULL, [AccountID] [int] NULL, [TransactionID] [varchar](255) NULL, [TransactionIDAlt] [nvarchar](50) NULL, [TransactionIDSpecific] [varchar](255) NULL, [Hash] varbinary(20) NULL, [Narrative] [nvarchar](510) NULL, [ActivityProfile] [int] NULL, [Amount] [money] NULL, [TransactionFee] [decimal](10, 2) NULL, [SaturationCount] [int] NULL, CONSTRAINT [PK_t_Transactions] PRIMARY KEY CLUSTERED ( [ID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY][/code][code="sql"]CREATE NONCLUSTERED INDEX [NCI_t_TransactionsHash] ON [dbo].[t_Transactions]( [Hash] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]GO[/code][code="sql"]CREATE NONCLUSTERED INDEX [NCI_t_TransactionsTransactionID] ON [dbo].[t_Transactions]( [TransactionID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]GO[/code][code="sql"]CREATE NONCLUSTERED INDEX [IX_t_TransactionsTransactionIDSpecific] ON [dbo].[t_Transactions]( [AccountID] ASC, [TransactionIDAlt] ASC, [TransactionID] ASC)INCLUDE ( [TransactionIDSpecific], [ActivityProfile], [Amount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]GO[/code][code="sql"]CREATE NONCLUSTERED INDEX [IX_t_TransactionsTransactionID] ON [dbo].[t_Transactions]( [AccountID] ASC, [TransactionID] ASC)INCLUDE ( [Amount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY][/code][code="sql"]CREATE PROCEDURE [dbo].DeleteAccount @AccountID INTASDELETEFROM dbo.t_TransactionsWHERE AccountID = @AccountID[/code][p]In this table we keep about 7 million rows for approximately 600 accounts. Some accounts have 10 or less transactions, some have half a million transactions. For all accounts, several times a day we refresh an account by deleting all transactions for an account and bulk insert fresh transactions from a csv. In the majority of cases, the transaction id's and much of the other information will be identical in value to what was deleted and the approximately the same amount of rows can be expected. The delete takes a disproportionate amount of time, increasingly so with each index we added. Cardinality on AccountID + TransactionID is very high. What could be done to increase the processing speed? Ideally I would like to have the effect of a truncate command but I cannot erase the accounts which I am not ready to bulk insert at that particular moment. Any ideas? Thanks![/p]
↧