标签:标识 tool pid role sql bsp use set mpi
SET IDENTITY_INSERT [UserRole] ON; SELECT ROW_NUMBER() OVER ( ORDER BY T1.ID ) i,T1.ID INTO #A FROM [GMSAccount].[dbo].[User] AS T1 JOIN [GMSToolManage].[dbo].[Manager] AS T2 ON T1.EmpID=T2.ID; DECLARE @count INT; SELECT @count=COUNT(1) FROM #A; DECLARE @tot INT; SELECT @tot=COUNT(1) FROM [GMSAccount].[dbo].[UserRole]; DECLARE @i INT=1; WHILE(@i<=@count) BEGIN INSERT INTO [GMSAccount].dbo.[UserRole](ID,UserID,RoleID) SELECT @i+@tot,ID,5 FROM #A WHERE i=@i; SET @i=@i+1; END; if OBJECT_ID(‘tempdb..#A‘) is not null drop table #A; SET IDENTITY_INSERT [UserRole] OFF; DBCC CHECKIDENT(UserRole)--修改标识列值
【SQL】把另一个数据库里的表A的信息在B表中提取出来,然后添加到C表。修改了标识列值
标签:标识 tool pid role sql bsp use set mpi
原文地址:https://www.cnblogs.com/Andrew-aq/p/12942775.html