Search code examples
keyibm-midrangedata-distribution-service

How to declare Foreign Key in a physical file through DDS in AS/400?


We can make foreign keys very easily using SQL. But is there any way to declare foreign key using DDS?


Solution

  • As IamLam pointed out, DDS doesn't directly support constraints in the source; you have to use ADDPFCST after the fact.

    I'm assuming you don't have a change management system. In that case, you could do one of two things

    Switch to SQL DDL - there's basically no difference between an SQL created table and DDS created file. IBM actually provides a utility to generate SQL DDL for an object regardless of rather or not it was created with DDS or DDL in the first place.

    Use a pre-compiler for your DDS. One open source one I've heard about is Alan Campin's COMPILE http://think400.dk/downloads.htm

    Actually you could use either of the above with a CMS also, but if you had a CMS you probably wouldn't be asking the question as it should take care of creating the constraint when the file is changed.