I have a login table into which all inserts are done by a single stored procedure.
CREATE TABLE dbo.LogTable(
LogRefnr int IDENTITY(1, 1) NOT NULL,
LogQuery varchar(255) NOT NULL,
LogTime datetime NOT NULL,
logQueryDuration int NULL,
LogSessionID int NULL,
CONSTRAINT PK_Log PRIMARY KEY CLUSTERED (LogRefnr)
)
go
Create procedure DBO.LogInsert ( @Query varchar(255), @time datetime, @duration int, @SessinID int) as
begin
Insert into LogTable ( LogRefnr, LogQuery, logQueryDuration, LogSessionID)
Values (@Query, @time, @duration, @SessinID);
end;
GO
Currently there are about 45500000 rows in that table and I want to direct logging to a different table.
My idea is to use the following script
begin Transaction
exec sp_rename LogTable, LogTableOld;
CREATE TABLE dbo.LogTable(
LogRefnr int IDENTITY(46000000, 1) NOT NULL, -- greater than select max(LogRefnr) from LogTableOld
LogQuery varchar(255) NOT NULL,
LogTime datetime NOT NULL,
logQueryDuration int NULL,
LogSessionID int NULL,
CONSTRAINT PK_Log2 PRIMARY KEY CLUSTERED (LogRefnr);
)
go
sp_recompile LogTable;
go
Commit;
Does this work and has minimal impact to other procedures calling LogInsert?