Skip to content

Latest commit

 

History

History
108 lines (85 loc) · 4.8 KB

File metadata and controls

108 lines (85 loc) · 4.8 KB
title getImportedKeys Method (SQLServerDatabaseMetaData) | Microsoft Docs
ms.custom
ms.date 01/19/2017
ms.prod sql
ms.prod_service connectivity
ms.reviewer
ms.technology connectivity
ms.topic conceptual
apiname
SQLServerDatabaseMetaData.getImportedKeys
apilocation
sqljdbc.jar
apitype Assembly
ms.assetid dc8c1a5e-700e-4059-a5ed-5013bbb87fb6
author David-Engel
ms.author v-daenge

getImportedKeys Method (SQLServerDatabaseMetaData)

[!INCLUDEDriver_JDBC_Download]

Retrieves a description of the primary key columns that are referenced by the foreign key columns in a table.

Syntax

  
public java.sql.ResultSet getImportedKeys(java.lang.String cat,  
                                          java.lang.String schema,  
                                          java.lang.String table)  

Parameters

cat

A String that contains the catalog name.

schema

A String that contains the schema name.

table

A String that contains the table name.

Return Value

A SQLServerResultSet object.

Exceptions

SQLServerException

Remarks

This getImportedKeys method is specified by the getImportedKeys method in the java.sql.DatabaseMetaData interface.

The result set returned by the getImportedKeys method will contain the following information:

Name Type Description
PKTABLE_CAT String The name of the catalog that contains the primary key table.
PKTABLE_SCHEM String The name of the schema of the primary key table.
PKTABLE_NAME String The name of the primary key table.
PKCOLUMN_NAME String The column name of the primary key.
FKTABLE_CAT String The name of the catalog that contains the foreign key table.
FKTABLE_SCHEM String The name of the schema of the foreign key table.
FKTABLE_NAME String The name of the foreign key table.
FKCOLUMN_NAME String The column name of the foreign key.
KEY_SEQ short The sequence number of the column in a multicolumn primary key.
UPDATE_RULE short The action applied to the foreign key when the SQL operation is an update. It can be one of the following values:

importedKeyNoAction (3)

importedKeyCascade (0)

importedKeySetNull (2)

importedKeySetDefault (4)

importedKeyRestrict (1)
DELETE_RULE short The action applied to the foreign key when the SQL operation is a deletion. It can be one of the following values:

importedKeyNoAction (3)

importedKeyCascade (0)

importedKeySetNull (2)

importedKeySetDefault (4)

importedKeyRestrict (1)
FK_NAME String The name of the foreign key.
PK_NAME String The name of the primary key.
DEFERRABILITY short Indicates if the evaluation of the foreign key constraint can be deferred until a commit. It can be one of the following values:

importedKeyInitiallyDeferred (5)

importedKeyInitiallyImmediate (6)

importedKeyNotDeferrable (7)

Note

For more information about the data returned by the getImportedKeys method, see "sp_fkeys (Transact-SQL)" in [!INCLUDEssNoVersion] Books Online.

Example

The following example demonstrates how to use the getImportedKeys method to return information about all the primary keys that reference the foreign keys of the Person.Address table in the [!INCLUDEssSampleDBnormal] sample database.

public static void executeGetImportedKeys(Connection con) {  
   try {  
      DatabaseMetaData dbmd = con.getMetaData();  
      ResultSet rs = dbmd.getImportedKeys("AdventureWorks", "Person", "Address");  
      ResultSetMetaData rsmd = rs.getMetaData();  
  
      // Display the result set data.  
      int cols = rsmd.getColumnCount();  
      while(rs.next()) {  
         for (int i = 1; i <= cols; i++) {  
            System.out.println(rs.getString(i));  
         }  
      }  
      rs.close();  
   }   
  
   catch (Exception e) {  
      e.printStackTrace();  
   }  
}  

See Also

SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members
SQLServerDatabaseMetaData Class