快速生成大量測試資料

2022-03-30 02:06:55 字數 666 閱讀 6294

sql是利用了oracle資料庫語法的幾個實用小技巧實現的:

1、利用oracle特有的「connect by」樹形連線語法生成測試記錄,「level <= 10」表示要生成10記錄;

2、利用rownum虛擬列生成遞增的整數資料;

3、利用sysdate函式加一些簡單運算來生成日期資料,本例中是每條記錄的時間加1秒;

4、利用dbms_random.value函式生成隨機的數值型資料,本例中是生成0到100之間的隨機整數;

5、利用dbms_random.string函式生成隨機的字元型資料,本例中是生成長度為20的隨機字串,字串中可以包括字元或數字。

那要生成10萬條測試記錄表可以用如下sql:

create table mytesttable as

select rownum as id,

to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,

trunc(dbms_random.value(0, 100)) as random_id,

dbms_random.string('x', 20) random_string

from dual

connect by level <= 100000;

oracle索引 快速生成大量測試資料

1.建立索引 create index on tablespace 2.刪除索引 drop index3.重置索引 alter index rebuild4.索引特點第一,通過建立唯一性索引,可以保證資料庫表中每一行資料的唯一性。第二,可以大大加快資料的檢索速度,這也是建立索引的最主要的原因。第三,...

以最快的方式生成大量的測試資料

use tempdb goif object id tempdb.tmp is not null drop table tmp gocreate table tmp id bigint identity 1,1 primary key,n nvarchar max go set nocount on...

快速生成測試資料

select rownum as id,to char sysdate rownum 24 3600,yyyy mm dd hh24 mi ss as inc datetime,trunc dbms random.value 0,100 as random id,dbms random.string...