SQL SERVER 实现多个数据库之间表的联系,利用临时表枚举表中行数据

--SET IDENTITY_INSERT [User] on;
SELECT ROW_NUMBER() OVER ( ORDER BY EmpID ) i,* INTO #A FROM [GMSToolManage].dbo.[employees];
DECLARE @count INT;
SELECT @count=COUNT(1) FROM #A; 
 
DECLARE @i INT=1;
DECLARE @ID INT;
WHILE(@i<=@count)
BEGIN
  INSERT INTO [GMSAccount].dbo.[User](ID,Workcell,EmpID,Name,Sex,PhoneNo,Birthday,LoginName) SELECT 
        @i+2,1,EmpID,Name,Sex,PhoneNo,Birthday,EmpID FROM #A WHERE i=@i;
  SET @i=@i+1;                                
END
UPDATE tb1
SET tb1.Password='96-E7-92-18-96-5E-B7-2C-92-A5-49-DD-5A-33-01-12', --111111
        tb1.Headportrait='\Upload\default.jfif',
        tb1.Email='default@default.com'
FROM [GMSAccount].dbo.[User] tb1
WHERE tb1.Workcell=1 
--if OBJECT_ID('tempdb..#A') is not null drop table #A;

 

posted @ 2020-05-22 23:44  aq_seabiscuit  阅读(254)  评论(0编辑  收藏  举报