1. 程式人生 > >sql語句插入百萬測試數據

sql語句插入百萬測試數據

百萬 eat name () 新建 spa 插入 sid 刪除

開發的過程中,很多時候我們需要插入百萬數據來測試功能和性能,今天我來教大家最簡單的插入方法

-----------------1、新建表---------------------

CREATE TABLE [student] (
[ID] [int]  IDENTITY (1, 1)  NOT NULL,
[sid] [varchar]  (20) NOT NULL,
[age] [int] NOT NULL,
[name] [nvarchar] (50) NOT NULL ) -----------------2、插入百萬數據--------------------- DECLARE
@LN VARCHAR(300),@MN VARCHAR(200),@FN VARCHAR(200) DECLARE @LN_N INT,@MN_N INT,@FN_N INT SET @LN=李王張劉陳楊黃趙周吳徐孫朱馬胡郭林何高梁鄭羅宋謝唐韓曹許鄧蕭馮曾程蔡彭潘袁於董余蘇葉呂魏蔣田杜丁沈姜範江傅鐘盧汪戴崔任陸廖姚方金邱夏譚韋賈鄒石熊孟秦閻薛侯雷白龍段郝孔邵史毛常萬顧賴武康賀嚴尹錢施牛洪龔 SET @MN=德紹宗邦裕傅家積善昌世貽維孝友繼緒定呈祥大正啟仕執必定仲元魁家生先澤遠永盛在人為任伐風樹秀文光謹潭棰 SET @FN=麗雲峰磊亮宏紅洪量良梁良糧靚七旗奇琪謀牟弭米密禰磊類蕾肋慶情清青興幸星刑
SET @LN_N=LEN(@LN) SET @MN_N=LEN(@MN) SET @FN_N=LEN(@FN) DECLARE @TMP VARCHAR(1000),@I INT SET @I=1 WHILE @I<1000000 BEGIN SET @TMP=CAST(SUBSTRING(@LN,CAST(RAND()*@LN_N AS INT),1) AS VARCHAR) SET @TMP=@TMP+CAST(SUBSTRING(@MN,CAST(RAND()*@MN_N AS INT),1) AS VARCHAR) SET @TMP=@TMP+CAST
(SUBSTRING(@FN,CAST(RAND()*@FN_N AS INT),1) AS VARCHAR) INSERT INTO student(sid,age,name)VALUES(‘2018-‘+convert(varchar,@I),cast(floor(rand() * 50+18) as int),@TMP)SET @I=@I+1 end -----------------統計--------------------- select COUNT(ID) from student -----------------查看--------------------- select top 100 * from student -----------------刪除表--------------------- drop table student

sql語句插入百萬測試數據