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