简体   繁体   English

我可以使用sql在AS400中创建“逻辑文件”吗?

[英]Can i create “logical files” in AS400 using sql?

I need to create as400 "logical files". 我需要创建as400“逻辑文件”。

my app connects to the db with jdbc. 我的应用程序使用jdbc连接到数据库。

Is it possible to create "logical files" with sql statements ? 是否可以使用sql语句创建“逻辑文件”?

If yes I would appreciate a sample statement. 如果是的话,我将感谢您的示例声明。

thanks 谢谢

I suggest making use of the CREATE INDEX SQL command from the green-screen STRSQL command. 我建议使用绿屏STRSQL命令中的CREATE INDEX SQL命令。 Then you can prompt it. 然后您可以提示它。 Here is an example of CREATE INDEX that let me query a 16 gigabyte file much faster. 这是CREATE INDEX的示例,它使我可以更快地查询16 GB的文件。 For this example, the physical file was the results of a database monitor than ran for a week: 对于此示例,物理文件是数据库监视程序的结果,而不是运行一周的结果:

CREATE INDEX QGPL.QZG0000016_QUERYJOB ON QGPL.QZG0000016
(QQJNUM ASC, QQUSER ASC, QQJOB ASC, QQUCNT ASC, QQRID ASC, QQI5 ASC)

The index itself took a long time to create, but subsequent queries based on the index were very fast. 索引本身需要很长时间才能创建,但是基于索引的后续查询非常快。

If you need to join multiple tables, plan ahead. 如果需要连接多个表,请提前计划。 Know the fields you will use to join the tables and create indexes against the joined tables. 了解将用于联接表并针对联接的表创建索引的字段。 You'll get the performance increase you're looking for. 您将获得所需的性能提升。 For an example, let's make up a query to show the items ordered by a customer: 例如,让我们组成一个查询来显示客户订购的商品:

SELECT ORDETAIL.ITEM_NAME, ORDETAIL.QUANTITY, ORHEADER.SHIPDATE
FROM ORHEADER
INNER JOIN ORDETAIL ON ORDETAIL.ORDERID = ORHEADER.ORDERID
WHERE ORHEADER.CUST_NUM = 123456

You would make the following indexes, if they didn't already exist: 如果不存在以下索引,则可以进行创建:

CREATE INDEX DATALIB.ORHEADER_BY_CUSTOMER ON DATALIB.ORHEADER (CUST_NUM ASC, ORDERID)
CREATE INDEX DATALIB.ORDETAIL_BY_ORDER ON DATALIB.ORDETAIL (ORDERID)

If you need to create a logical file select/omit criteria, then you need to create a view. 如果需要创建逻辑文件选择/省略条件,则需要创建视图。 A view is not an index, though, and you can't mix an index and a view like you can with a keyed logical with select/omits. 但是,视图不是索引,并且不能像使用选择/省略键控逻辑那样将索引和视图混合使用。 For that, a DDS spec is still the best. 为此,DDS规范仍然是最好的。

This will help if you are trying to an order by on your view, but will not really help if you have a performance issue. 如果您尝试根据自己的观点进行订购,这将有所帮助,但是如果您遇到性能问题,则将无济于事。

Sample of data basetable : 数据库表basetable

A 
B 
C 
A 
A 
A 

Query: 查询:

create view myview1  as                   
select lib                                
from(                                     
  SELECT rank() over(order by lib), lib   
FROM basetable) a   

Sample of data from myview1 来自myview1的数据myview1

A 
A 
A 
A 
B 
C 

To achieve much of the same effect, I've created database views over all the tables in an AS/400 DB2, mapping more understandable names to the physical ones. 为了达到相同的效果,我在AS / 400 DB2中的所有表上创建了数据库视图,将更易理解的名称映射到物理名称。 I don't think views are logical files, but I'm just a user of said AS/400 and know exactly as much about it as needed to interact with the data. 我认为视图不是逻辑文件,但是我只是所说的AS / 400的用户,并且与数据交互所需的信息非常了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM