一定要自己试过才知道么? 你也没试过吃屎,你怎么知道屎不能吃,难道你试过啊...(没有愤怒的意思)
declare @name nvarchar(100),@email nvarchar(100),@LastLoginIP nvarchar(100) declare cursor_data CURSOR FOR SELECT [UserName],[Email],[LastLoginIP] FROM [dbo].[Users] --数据源 open cursor_data fetch from cursor_data into @name,@email,@LastLoginIP --遍历一行值 while @@fetch_status = 0 begin print @name --添加管理员 INSERT INTO [dbo].[Administrator] ([AdministratorName] ,[NickName] ,[SiteId] ,[AdministratorPassword] ,[Email] VALUES (@name ,@name ,1 ,'XXXXXXX' ,@email) --得到管理员ID declare @maxid int select top 1 @maxid = AdministratorId from [dbo].[Administrator] order by AdministratorId desc print convert(nvarchar(100),@maxid) --添加管理员角色关联表 INSERT INTO [dbo].[AdministratorRole] ([RoleId] ,[AdministratorId]) VALUES (4 ,@maxid) fetch from cursor_data into @name,@email,@LastLoginIP end close cursor_data deallocate cursor_data
declare @id int declare cursor_data CURSOR FOR SELECT ID FROM [dbo].Courses --数据源 open cursor_data fetch from cursor_data into @id --遍历一行值 while @@fetch_status = 0 begin update Courses set Volumes = (select count(1) from Volumes where CourseID = @id) where ID = @id fetch from cursor_data into @id end close cursor_data deallocate cursor_data