Ребята, такая задача: есть таблица Services (id_serv PK, title, description, cost_per_unit, id_category), данные в которую заносятся через функцию
В коде идет генерация случайных названий, идет проверка на пустые строки. Но строки в таблице повторяются, как добавить уникальность??? данных в таблице 1 млн.
declare @id_serv int, @id_cat int, @title nchar(15), @desc nchar(40), @cost smallmoney, @_title nchar(15), @_desc nchar(40);
set @id_serv=0
set @id_cat=1
set @title=N'abcdefghijklmnopqrstuvwxyz0123456789'
set @desc = @title + @title
set @cost=100
while @id_serv<1000000
begin
set @id_cat=Rand()*10
set @_title=SUBSTRING(@title,(Cast((RAND()*10) as int)),(Cast((RAND()*12) as int)))
while ((@_title=null or (@_title=N'% %' or @_title=N'_ ' or @_title=N' _' or @_title=N' ' or @_title=N'% ' or @_title=N' %') or @_title=''))
begin
set @_title=SUBSTRING(@title,(Cast((RAND()*10) as int)),(Cast((RAND()*12) as int)))
if((@_title!=null) or(@_title!=N'% %' or @_title!=N'_ ' or @_title!=N' _' or @_title!=N' ' or @_title!=N'% ' or @_title!=N' %') or @_title!='') break else continue
end
set @_desc=SUBSTRING(@desc,(Cast((RAND()*10) as int)),(Cast((RAND()*12) as int)))
while (@_desc=null or (@_desc=N'% %' or @_desc=N'_ ' or @_desc=N' _' or @_desc=N' ' or @_desc=N'% ' or @_desc=N' %') or @desc='')
begin
set @_desc=SUBSTRING(@desc,(Cast((RAND()*10) as int)),(Cast((RAND()*12) as int)))
if((@_desc!=null) or(@_desc!=N'% %' or @_desc!=N'_ ' or @_desc!=N' _' or @_desc!=N' ' or @_desc!=N'% ' or @_desc!=N' %') or @desc!='') break else continue
end
set @cost=(Cast((RAND()*1300) as int))
insert into Services values (@_title,@_desc,@cost,@id_cat)
set @id_serv=@id_serv+1
end