Hi.
We like very much an int id instead of computername, so this is a good change, but this will do the same as the cursor proc
CREATE TABLE dbo.Tmp_Computers
(
[Computername] [int] IDENTITY(1,1) NOT NULL,
[ComputerUnique] [nvarchar](150) NULL,
[Domain] [nvarchar](300) NULL,
[Userdomain] [nvarchar](150) NULL,
[Username] [nvarchar](150) NULL,
[Lastseen] [datetime] NULL DEFAULT (getdate()),
[Firstseen] [datetime] NULL DEFAULT (getdate()),
[Lasttriggered] [datetime] NULL,
[LastScheduled] [datetime] NULL,
[LastActiveScan] [datetime] NULL,
[FQDN] [nvarchar](512) NULL,
[LastknownIP] [varchar](100) NULL,
[Computer] [nvarchar](150) NULL,
[SiteID] [numeric](18, 0) NULL,
[Scanserver] [nvarchar](150) NULL,
[ReplID] [numeric](18, 0) NULL,
[ReplSite] [numeric](18, 0) NULL,
[OScode] [varchar](20) NULL,
[SP] [numeric](18, 0) NULL,
[Description] [nvarchar](300) NULL
) ON [PRIMARY]
go
-- SET IDENTITY_INSERT Tmp_Computers ON
go
IF EXISTS(SELECT * FROM tblcomputers)
INSERT INTO Tmp_Computers ( ComputerUnique,
[Domain],Userdomain,Username,Lastseen,Firstseen,Lasttriggered,
LastScheduled,LastActiveScan,FQDN,LastknownIP,Computer,SiteID)
SELECT ComputerUnique,
[Domain],Userdomain,Username,Lastseen,Firstseen,Lasttriggered,
LastScheduled,LastActiveScan,FQDN,LastknownIP,Computer,SiteID FROM dbo.tblcomputers TABLOCKX
go
SET IDENTITY_INSERT Tmp_Computers OFF
DROP TABLE tblcomputers
go
Exec sp_rename 'Tmp_Computers', 'tblcomputers'
GO
This is finished in 6 seconds, and later you update the id in the other tables so as far as I can see from your script this will work fine.
All I do is to let SQL create the id column
I am going to try this 🙂