SQL Server數(shù)據(jù)庫如何使用存儲過程造批量數(shù)據(jù)
作者:shenzhen2008
本文介紹一個(gè)SQL Server數(shù)據(jù)庫使用存儲過程造批量數(shù)據(jù)的實(shí)例,通過它讓我們來了解一下如何用存儲過程生成批量數(shù)據(jù)的方法,希望能夠?qū)δ兴鶐椭?/div>
我們知道,在SQL Server數(shù)據(jù)庫操作中,有時(shí)候需要我們生成大量的數(shù)據(jù),比如說在做性能測試的時(shí)候,經(jīng)常會遇到需要大量的數(shù)據(jù)用來做交易,例如銀行的繳費(fèi),當(dāng)一條數(shù)據(jù)繳完后就不能再繳費(fèi)了,所以需要造大量的數(shù)據(jù)用來做性能測試,本文我們通過做某銀行校園卡繳費(fèi)性能測試,根據(jù)表的特點(diǎn),編寫的一個(gè)存儲過程,代碼如下:
- declare
- busiId varchar2(20);
- corpId varchar2(20);
- termId varchar2(10);
- collegeId varchar(30);
- collegeName varchar(40);
- stuId varchar2(30);
- begin
- busiId := '100104'; --業(yè)務(wù)代碼
- corpId := 'E000000059'; --委托單位
- termId := '0101'; --學(xué)期
- collegeId := '010590'; --學(xué)校代碼
- collegeName := '深圳大學(xué)';
- stuId := '59';
- --增加學(xué)校信息
- 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');
- --增加學(xué)校費(fèi)項(xiàng)信息
- 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,'費(fèi)項(xiàng)'||fee_num);
- end loop;
- --增加學(xué)生繳費(fèi)信息
- 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', '計(jì)算機(jī)科學(xué)', '計(jì)算機(jī)',
- '測試'||student_num, '4', '0');
- --增加學(xué)生費(fèi)項(xiàng)繳費(fèi)信息
- 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ù)的方法了,本文就介紹到這里,希望能夠給您帶來一些收獲。
【編輯推薦】
責(zé)任編輯:趙鵬
來源:
CSDN博客


相關(guān)推薦




