Skip to content

DF_FILE_NUMBER_SQL_RELATIONS

The number of columns in the table that are part of a foreign key.

Level

Table

Supported by

The DataFlex SQL Drivers (SQL Server, DB2, and ODBC)

Type

Integer, permanent

Access

Read Only

Values

1 ~ maximum number of columns allowed in the database

Syntax

Use cli.pkg
Get_Attribute DF_FILE_NUMBER_SQL_RELATIONS of {tableNumber} to {IntegerVariable}

Remarks

When a table is opened, the foreign key information is retrieved from the back end. This information can be used to examine the relationships as they are defined on the back end.

Procedure ShowSQLRelations Handle hTable
    Integer iNumRelations
    Integer iFKColumn
    String sFkTable
    String sFKSchema
    String sFKColumn
    String sPKSchema
    String sPKTable
    String sPKColumn
    Integer iCurRel

    Move 0 To hTable
    Repeat
        Get_Attribute DF_FILE_NEXT_OPENED Of hTable To hTable
        If (hTable <> 0) Begin
            Get_Attribute DF_FILE_NUMBER_SQL_RELATIONS Of hTable To iNumRelations
            If (iNumRelations > 0) Begin
                Get_Attribute DF_FILE_TABLE_NAME Of hTable To sFKTable
                Get_Attribute DF_FILE_OWNER Of hTable To sFKSchema
                For iCurRel From 1 To iNumRelations
                    Get_Attribute DF_SQL_RELATION_COLUMN Of hTable iCurRel To iFKColumn
                    Get_Attribute DF_SQL_RELATION_RELATED_SCHEMA Of hTable iCurRel To sPKSchema
                    Get_Attribute DF_SQL_RELATION_RELATED_TABLE Of hTable iCurRel To sPKTable
                    Get_Attribute DF_SQL_RELATION_RELATED_COLUMN Of hTable iCurRel To sPKColumn
                    Get_Attribute DF_FIELD_NAME Of hTable iFKColumn To sFKColumn
                    Showln sFKSchema "." sFKTable "." sFKColumn " relates to " sPKSchema "." sPKTable "." sPKColumn
                Loop
            End
        End
    Until (hTable = 0)
End_Procedure // ShowSQLRelations

The sample procedure above shows all columns that are part of a foreign key of the given table.