38 lines
816 B
Transact-SQL
38 lines
816 B
Transact-SQL
USE [envisage]
|
|
Go
|
|
|
|
declare @roles table (
|
|
ID INT IDENTITY (1, 1) NOT NULL,
|
|
Name nvarchar(4000),
|
|
[Count] int
|
|
);
|
|
insert into @roles
|
|
select Name,count(Name) from AspNetRoles group by Name having count(name) > 1
|
|
|
|
|
|
|
|
declare @i int=1
|
|
declare @max int
|
|
select @max=count(ID) FROM @roles
|
|
declare @OnName nvarchar(4000)
|
|
declare @roleIdx int=1
|
|
while ( @i <=@max)
|
|
begin
|
|
declare @count int
|
|
declare @Name nvarchar(4000)
|
|
declare @Id nvarchar(128)
|
|
select @Name=Name,@count=[count] from @roles where ID=@i
|
|
set @roleIdx=1
|
|
while @roleIdx < @count
|
|
begin
|
|
SET @Id=''
|
|
select top 1 @Id=Id from AspNetRoles where Name=@Name
|
|
if not isnull(@Id,'') = ''
|
|
begin
|
|
UPDATE AspNetRoles set Name=@Name+'_'+convert(nvarchar,@roleIdx) where Id=@Id
|
|
end
|
|
set @roleIdx=@roleIdx+1
|
|
end
|
|
set @i=@i+1
|
|
|
|
end |