• I've been playing with this sort of thing for a while.

    1. Identify missing primary keys and unique constraints
    2. Identify the number of fields in the key
    3. Identify naming conventions for primary key fields and the equivalent in other tables
    4. [Identify candidate FK where a table contains the equivalent fields as those participating in aa PK[/li]

    5. Discount those where there is already an FK relationship
    6. Test the data to precheck violations
    7. Generate PK & FK scripts through automated means

    Text parsing SYS.comments for joins in views should also help Identify candidates but is significantly more involved.

    I Have a working box of bits for Vertica,, Teradata, MySql, SQL server and I'm looking to experiment with RedShift in the near future. I think working out how to do this for Postgres would be handy.