0

純粋に SQL Server 上にあるデータベース システムを作成する必要があります。診断ラボについてです。少なくとも 40,000 の個別の患者レコードが含まれている必要があります。自動生成された ID、名前、生年月日、年齢、電話番号を含む「Patient」という名前のテーブルがあります。私たちの先生は、それぞれ 200 の名前を持つ 2 つの一時テーブルを含むダミーのストアド プロシージャを提供してくれました。同じダミー ストアド プロシージャを使用し、テーブルに従って修正しました。しかし、挿入される行は毎回 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
4

1 に答える 1

4

タイプUNION ALLを見逃している可能性があります-

Select 'Julianne' Union All 
Select 'Sharyl' Union All 
Select 'Yoshie' Union All 
Select 'Germaine' Union All 
Select 'Ja' Union All
Select 'Kandis' --<-- missing union all
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'

これを試してください(WHILEと追加の変数なし):

DECLARE @tFirstNames TABLE (FirstName VARCHAR(50) NOT NULL)
INSERT INTO @tFirstNames (FirstName)
VALUES 
    ('Julianne'), ('Sharyl'), ('Yoshie'), ('Germaine'), 
    ('Ja'), ('Kandis'), ('Hannelore'), ('Laquanda'), ('Clayton'), 
    ('Ollie'), ('Rosa'), ('Deloras'), ('April'), ('Garrett'), 
    ('Mariette'), ('Carline')

DECLARE @tLastNames TABLE (LastName VARCHAR(50) NOT NULL)
INSERT INTO @tLastNames (LastName)
VALUES 
    ('Brown'), ('Chrichton'), ('Bush'), ('Clinton'), 
    ('Blair'), ('Wayne'), ('Hanks'), ('Cruise'), ('Campbell'), 
    ('Turow'), ('Tracey'), ('Arnold'), ('Derick'), 
    ('Nathanael'), ('Buddy') 

INSERT INTO dbo.Patient (...) 
SELECT 
      -- Possible problem: String or binary data would be truncated 
      d.FLName -- <-- FirstName + LastName i.e. 50 + 1 + 50 = 101 chars
    , d.Age
    , Gender = CASE ABS(CAST((BINARY_CHECKSUM(NEWID(), NEWID())) AS INT)) % 3
                    WHEN 0 THEN 'Male'
                    ELSE 'Female'
               END
    , (ABS(CAST((BINARY_CHECKSUM(NEWID(), NEWID())) AS INT)) % 8888889) + 1111111
    , BirthDay = CONVERT(VARCHAR(10), DATEADD( year, -d.Age, GETDATE()), 112)
FROM (
    SELECT 
          FLName = f.FirstName + ' ' + l.LastName
        , Age = (ABS(CAST((BINARY_CHECKSUM(f.FirstName, NEWID())) AS INT)) % 70) + 10
    FROM @tFirstNames f
    CROSS JOIN @tLastNames l
) d
于 2013-05-14T17:30:12.590 に答える