我可以在表中添加什么索引:
CREATE TABLE [WData](
[Account] [varchar](50) NOT NULL,
[Table] [varchar](50) NOT NULL,
[BatchID] [datetime2](7) NOT NULL,
[XmlRow] [xml] NULL
) ON [PRIMARY]
以便后续存储过程运行得更快?现在速度很慢。
create PROCEDURE [Update_WData]
@Account VARCHAR(50),
@Table VARCHAR(50),
@BatchID DATETIME2,
@XmlRows xml
AS
BEGIN
SET NOCOUNT ON;
DECLARE @input TABLE (
[XmlRow] xml NULL
);
INSERT INTO @input (XmlRow)
SELECT
c1.query('.')
FROM @XmlRows.nodes('/Block/NewRow') AS t(c1);
DECLARE @output TABLE ([ACTION] NVARCHAR(50) );
MERGE WData AS t
USING @input AS s
ON (t.Account = @Account AND t.[Table]=@Table AND CONVERT(VARCHAR(max),t.XmlRow)=CONVERT(VARCHAR(max),s.XmlRow))
WHEN NOT MATCHED BY TARGET
THEN INSERT (Account,[Table],BatchID, [XmlRow])
VALUES (@Account, @Table, @BatchID, s.XmlRow )
WHEN MATCHED AND t.BatchID <> @BatchID
THEN UPDATE SET t.BatchID = @BatchID
OUTPUT
$ACTION
INTO @output;
SELECT [Action], COUNT(*) AS [Count]
FROM @Output
GROUP BY [Action]
END