我必须创建一个纯粹基于 SQL Server 的数据库系统。这是关于一个诊断实验室。它应包含至少 40,000 条不同的患者记录。我有一个名为“Patient”的表,其中包含自动生成的 ID、姓名、出生日期、年龄和电话号码。我们的老师为我们提供了一个虚拟存储过程,其中包含 2 个临时表,每个表有 200 个名称,最后他制作了一个笛卡尔积,应该给出 40,000 个不同的行。我使用了相同的虚拟存储过程并根据我们的表格对其进行了修改。但是每次插入的行数只有 1260。每次我们运行查询时,它不会给我们超过 1260 条记录。我添加了一部分临时名称表和存储过程。
Declare @tFirstNames Table( FirstName Varchar(50) Not Null )
Declare @tLastNames Table ( LastName Varchar(50) Not Null )
Declare @tNames Table ( Id Int Identity Not Null, Name Varchar(50) Not Null)
Insert Into @tFirstNames (FirstName)
Select 'Julianne' Union All Select 'Sharyl' Union All Select 'Yoshie'
Union All Select 'Germaine' Union All Select 'Ja' Union All
Select 'Kandis' Select 'Hannelore' Union All Select 'Laquanda' Union All
Select 'Clayton' Union All Select 'Ollie' Union All
Select 'Rosa' Union All Select 'Deloras' Union All
Select 'April' Union All Select 'Garrett' Union All
Select 'Mariette' Union All Select 'Carline' Union All
Insert Into @tLastNames (LastName)
Select 'Brown' Union All Select 'Chrichton' Union All Select 'Bush'
Union All Select 'Clinton' Union All Select 'Blair'
Union All Select 'Wayne' Union All Select 'Hanks'
Union All Select 'Cruise' Union All Select 'Campbell'
Union All Select 'Turow' Union All Select 'Tracey'
Union All Select 'Arnold' Union All Select 'Derick'
Union All Select 'Nathanael' Union All Select 'Buddy'
Insert Into @tNames
Select FirstName + ' ' + LastName
From @tFirstNames, @tLastNames
Declare @iIndex Integer
Declare @iPatientTotalRecords Integer
Declare @vcName Varchar(50)
Declare @iAge Integer
--Set @iIndex = 1
Select @iPatientTotalRecords = Max(Id), @iIndex = Min(Id) From @tNames
While @iIndex <= @iPatientTotalRecords
Begin
Select @vcName = Name From @tNames Where Id = @iIndex
Set @iAge = Cast( Rand() * 70 As Integer ) + 10
Insert into Patient values
(@vcName, @iAge,
Case Cast( Rand() * 3 As Integer)
When 0 Then 'Male'
When 1 Then 'Female'
Else 'Female'
End,
Cast( Rand() * 8888889 As Integer ) + 1111111, DateAdd ( year, -@iAge, GetDate()))
Set @iIndex = @iIndex + 1
End