27,579
社区成员
发帖
与我相关
我的任务
分享
if OBJECT_ID('code','u') is not null
drop table code
go
create table code
(
ID int identity(1,1) not null,
Code varchar(8) not null,
VGUID uniqueidentifier default(newid()) not null
)
insert into code(Code) values (LEFT(NEWID(),8))
DECLARE @a VARCHAR(8)
A:
SELECT @a=left(NEWID(),8)
IF EXISTS(SELECT 1 FROM Code WHERE code=@a)
GOTO A
INSERT Code(Code) SELECT @a