SQL Server數(shù)據(jù)庫如何使用存儲過程造批量數(shù)據(jù)
作者:shenzhen2008
本文介紹一個SQL Server數(shù)據(jù)庫使用存儲過程造批量數(shù)據(jù)的實例,通過它讓我們來了解一下如何用存儲過程生成批量數(shù)據(jù)的方法,希望能夠?qū)δ兴鶐椭?/div>
我們知道,在SQL Server數(shù)據(jù)庫操作中,有時候需要我們生成大量的數(shù)據(jù),比如說在做性能測試的時候,經(jīng)常會遇到需要大量的數(shù)據(jù)用來做交易,例如銀行的繳費,當一條數(shù)據(jù)繳完后就不能再繳費了,所以需要造大量的數(shù)據(jù)用來做性能測試,本文我們通過做某銀行校園卡繳費性能測試,根據(jù)表的特點,編寫的一個存儲過程,代碼如下:
- declare
- busiId varchar2(20);
- corpId varchar2(20);
- termId varchar2(10);
- collegeId varchar(30);
- collegeName varchar(40);
- stuId varchar2(30);
- begin
- busiId := '100104'; --業(yè)務代碼
- corpId := 'E000000059'; --委托單位
- termId := '0101'; --學期
- collegeId := '010590'; --學校代碼
- collegeName := '深圳大學';
- stuId := '59';
- --增加學校信息
- insert into
- bib_booking_coll_info(busi_id,corp_id,term_id,term_flag,college_id,college_name,start_date,end_date)
- values(busiId,corpId,termId,'1',collegeId,collegeName,'20110520','20110527');
- --增加學校費項信息
- for fee_num in 1..4 loop
- insert into bib_coll_fee_info(busi_id,corp_id,cost_code,cost_name)
- values(busiId,corpId,'100'|| fee_num,'費項'||fee_num);
- end loop;
- --增加學生繳費信息
- for student_num in 1..100000 loop
- insert into bib_booking_student_info
- (busi_id, corp_id, term_id, stu_id, college_id, bank_acnt, stu_dep, stu_speciality,
- stu_name, need_totalamt, stu_stat)
- values
- (busiId, corpId, termId, stuId||lpad(student_num,'6','0'), collegeId, '6029071032159548', '計算機科學', '計算機',
- '測試'||student_num, '4', '0');
- --增加學生費項繳費信息
- for stu_fee in 1..4 loop
- insert into bib_booking_fee_info
- (busi_id, corp_id, term_id, stu_id, cost_code, college_id, cost_amt, stu_stat)
- values
- (busiId, corpId, termId, stuId||lpad(student_num,'6','0'), '100'|| stu_fee, collegeId, '1', '0');
- end loop;
- end loop;
- commit;
- end;
看過以上的代碼,相信大家一定能了解SQL Server數(shù)據(jù)庫用存儲過程生成大量數(shù)據(jù)的方法了,本文就介紹到這里,希望能夠給您帶來一些收獲。
【編輯推薦】
責任編輯:趙鵬
來源:
CSDN博客


相關推薦




