1、生成表结构
[db2inst2@localhost ~]$vi create.sql
CREATE TABLE EMPL (ENO INTEGER, LASTNAME VARCHAR(30),
HIREDATE DATE, SALARY INTEGER);
[db2inst2@localhost ~]$
2、随机生成测试数据:(10000条数据)
INSERT INTO EMPL
-- generate 100 records
WITH DT(ENO) AS (VALUES(1) UNION ALL SELECT ENO+1 FROM DT WHERE ENO <
10000 )
-- Now, use the generated records in DT to create other columns
-- of the employee record.
SELECT ENO,
TRANSLATE(CHAR(INTEGER(RAND()*1000000)),
CASE MOD(ENO,4) WHEN 0 THEN 'aeiou' || 'bcdfg'
WHEN 1 THEN 'aeiou' || 'hjklm'
WHEN 2 THEN 'aeiou' || 'npqrs'
ELSE 'aeiou' || 'twxyz' END,
'1234567890') AS LASTNAME,
CURRENT DATE - (RAND()*10957) DAYS AS HIREDATE,
INTEGER(10000+RAND()*200000) AS SALARY
FROM DT;
3、生成结果:
[db2inst2@localhost ~]$
db2 "select count(1) from empl "
1
-----------
10000
1 条记录已选择。
[db2inst2@localhost ~]$ db2 "select * from empl desc fetch first 10 rows only "
ENO LASTNAME HIREDATE SALARY
----------- ------------------------------ ---------- -----------
27 wttwwu 2009-12-14 11593
28 bugfie 1988-03-19 103893
29 emhojm 1994-03-30 94836
30 eqeeip 2006-02-03 95374
31 yezeia 2011-10-19 143616
32 fadfge 1992-04-14 84165
33 kmihhj 1995-07-07 43699
34 aareun 1990-05-14 168340
35 wiuwuu 2003-05-15 99121
36 duuidg 1995-08-02 72734
10 条记录已选择。
阅读(3030) | 评论(0) | 转发(0) |