初始化用户表和房间表的代码 以备忘

declare @user_id int;
declare @str_user_id varchar(16);
declare @room_id int;


--删除用户表原有的数据,并初始化用户表
DELETE FROM [User]

SET @user_id=1;
SET @room_id=1;

WHILE @room_id<=10
BEGIN

WHILE @user_id <=100
BEGIN
SET @str_user_id=CONVERT(varchar,@room_id)+CONVERT(varchar,@user_id);
INSERT [User] (User_Id ,User_Password ,User_Name ,User_State ,User_Photo,User_Sex ,Room_Id)
VALUES(@str_user_id ,'000000',@str_user_id ,CAST(FLOOR(RAND()*10) as int)%4, @user_id%20,CAST(FLOOR(RAND()*10) as int)%2, @room_id);
SET @user_id=@user_id+1;
END

SET @room_id=@room_id+1;
END


--删除房间表原有数据,并初始化房间表
DELETE FROM [Room]
SET @room_id=1;
SET @user_id=1;

declare @str_room_host varchar(16);
declare @str_room_name varchar(16);

WHILE @room_id<=10
BEGIN
SET @str_room_name='房间'+CONVERT(varchar,@room_id);
INSERT [Room] (Room_Id ,Room_Name ,Room_Host )
VALUES(@room_id,@str_room_name,CONVERT(varchar,@room_id)+'-1');
SET @room_id =@room_id+1;
END

你可能感兴趣的:(数据库)