有没有办法更有效地生成一百万个 MAC 地址?
这是我正在做的事情,但是生成一百万个 MAC 地址并将它们插入到我的表中需要大约 10 分钟:
DECLARE @StartRange BINARY(6)
DECLARE @EndRange BINARY(6)
SET @StartRange = 0x0036D1F00000
SET @EndRange = 0x0036D1FFFFFF
--select convert(bigint,+ @EndRange) - convert(bigint,+ @StartRange) = 1048575
WHILE(convert(bigint, (SELECT IDENT_CURRENT('Mac_Address'))) < (convert(bigint, @EndRange) - convert(bigint, @StartRange)))
BEGIN
insert into Mac_Address (MacAddress)
select convert(BINARY(6),(convert(bigint, (SELECT IDENT_CURRENT('Mac_Address'))) + convert(bigint, @StartRange)))
END
这是我在网上找到的执行此操作的代码,它会在几秒钟内执行。但是它正在将 MAC 地址生成到系统表中:
DECLARE @StartRange BINARY(8)
DECLARE @EndRange BINARY(8)
SET @StartRange = 0x00000004A500114B
SET @EndRange = 0x00000004A50F11FF
--select convert(integer,+ @EndRange) - convert(integer,+ @StartRange) = 983220
select convert(BINARY(8),RW + convert(integer, @StartRange))
from
(select row_number() over(order by a.id) As RW from syscolumns,syscolumns a,syscolumns b ,syscolumns c) b --I do not understand this line very well.
where RW between 1 and (convert(integer, @EndRange) - convert(integer, @StartRange))