declare @CourseNum int
declare @ChapterNum int
set @ChapterNum=1
set @CourseNum=1
while(@courseNum<=10)
begin
declare @courseName varchar(30)
set @CourseName='Course'+Convert(Varchar(30),@courseNum)
insert into course values(@CourseName)
while(@ChapterNum<=20)
begin
declare @ChapterName varchar(40)
set @ChapterName=@courseName+'_Chapter'+Convert(Varchar(30),@ChapterNum)
insert into chapter values(@ChapterName,@CourseNum)
set @ChapterNum=@ChapterNum+1
continue
end
set @ChapterNum=1---一定要重置一下 否则它再第一次循环后一直保持为20
set @courseNum=@courseNum+1
continue
end
select * from chapter
declare @ChapterNum int
set @ChapterNum=1
set @CourseNum=1
while(@courseNum<=10)
begin
declare @courseName varchar(30)
set @CourseName='Course'+Convert(Varchar(30),@courseNum)
insert into course values(@CourseName)
while(@ChapterNum<=20)
begin
declare @ChapterName varchar(40)
set @ChapterName=@courseName+'_Chapter'+Convert(Varchar(30),@ChapterNum)
insert into chapter values(@ChapterName,@CourseNum)
set @ChapterNum=@ChapterNum+1
continue
end
set @ChapterNum=1---一定要重置一下 否则它再第一次循环后一直保持为20
set @courseNum=@courseNum+1
continue
end
select * from chapter