src/PDO/SchemaPDOMssql.php
/**
     * Collects the foreign key column details for the given table.
     *
     * @param TableSchema $table the table metadata
     *
     * @throws Exception|InvalidConfigException|Throwable
     */
Collects the foreign key column details for the given table.
@param TableSchema $table the table metadata


Collects the foreign key column details for the given table . @param TableSchema $table the table metadata
protected function findForeignKeys(TableSchema $table): void
    {
        $object = $table->getName();
        if ($table->getSchemaName() !== null) {
            $object = $table->getSchemaName() . '.' . $object;
        }
        if ($table->getCatalogName() !== null) {
            $object = $table->getCatalogName() . '.' . $object;
        }
        $sql = <<<SQL
SELECT
	[fk].[name] AS [fk_name],
	[cp].[name] AS [fk_column_name],
	OBJECT_NAME([fk].[referenced_object_id]) AS [uq_table_name],
	[cr].[name] AS [uq_column_name]
FROM
	[sys].[foreign_keys] AS [fk]
	INNER JOIN [sys].[foreign_key_columns] AS [fkc] ON
		[fk].[object_id] = [fkc].[constraint_object_id]
	INNER JOIN [sys].[columns] AS [cp] ON
		[fk].[parent_object_id] = [cp].[object_id] AND
		[fkc].[parent_column_id] = [cp].[column_id]
	INNER JOIN [sys].[columns] AS [cr] ON
		[fk].[referenced_object_id] = [cr].[object_id] AND
		[fkc].[referenced_column_id] = [cr].[column_id]
WHERE
	[fk].[parent_object_id] = OBJECT_ID(:object)
SQL;
        $rows = $this->db->createCommand($sql, [':object' => $object])->queryAll();
        $table->foreignKeys([]);
        foreach ($rows as $row) {
            if (!isset($table->getForeignKeys()[$row['fk_name']])) {
                $fk[$row['fk_name']][] = $row['uq_table_name'];
                $table->foreignKeys($fk);
            }
            $fk[$row['fk_name']][$row['fk_column_name']] = $row['uq_column_name'];
            $table->foreignKeys($fk);
        }
    }
protected function findForeignKeys ( TableSchema $ table ) : void { $ object = $ table -> getName ( ) ; if ( $ table -> getSchemaName ( ) !== null ) { $ object = $ table -> getSchemaName ( ) . '.' . $ object ; } if ( $ table -> getCatalogName ( ) !== null ) { $ object = $ table -> getCatalogName ( ) . '.' . $ object ; } $ sql = <<< SQL SELECT 	[fk].[name] AS [fk_name], 	[cp].[name] AS [fk_column_name], 	OBJECT_NAME([fk].[referenced_object_id]) AS [uq_table_name], 	[cr].[name] AS [uq_column_name] FROM 	[sys].[foreign_keys] AS [fk] 	INNER JOIN [sys].[foreign_key_columns] AS [fkc] ON 		[fk].[object_id] = [fkc].[constraint_object_id] 	INNER JOIN [sys].[columns] AS [cp] ON 		[fk].[parent_object_id] = [cp].[object_id] AND 		[fkc].[parent_column_id] = [cp].[column_id] 	INNER JOIN [sys].[columns] AS [cr] ON 		[fk].[referenced_object_id] = [cr].[object_id] AND 		[fkc].[referenced_column_id] = [cr].[column_id] WHERE 	[fk].[parent_object_id] = OBJECT_ID(:object) 
SQL ; $ rows = $ this -> db -> createCommand ( $ sql , [ ':object' => $ object ] ) -> queryAll ( ) ; $ table -> foreignKeys ( [ ] ) ; foreach ( $ rows as $ row ) { if ( ! isset ( $ table -> getForeignKeys ( ) [ $ row [ 'fk_name' ] ] ) ) { $ fk [ $ row [ 'fk_name' ] ] [ ] = $ row [ 'uq_table_name' ] ; $ table -> foreignKeys ( $ fk ) ; } $ fk [ $ row [ 'fk_name' ] ] [ $ row [ 'fk_column_name' ] ] = $ row [ 'uq_column_name' ] ; $ table -> foreignKeys ( $ fk ) ; } }
Collects the foreign key column details for the given table.
Collects the foreign key column details for the given table .
/**
         * Please refer to the following page for more details:
         * {@see http://msdn2.microsoft.com/en-us/library/aa175805(SQL.80).aspx}
         */