About qualifying table and field names
Geodatabases that reside in a relational database management system (RDBMS), such as Oracle, SQL Server, or IBM DB2, use standard database naming conventions for identifying tables for specific users. A RDBMS can contain thousands of tables from multiple users; therefore, users of an enterprise geodatabase must understand how to correctly qualify the name of an object so the correct feature class, relationship class, feature dataset, or table is used during an operation.
If an unqualified name is specified as input to a tool, the geoprocessor qualifies it automatically using the currently connected user name, which is specified as a property of the connected workspace. If a program needs to access data from a number of users, it should qualify the name of the table using the geoprocessor's QualifyTableName method so the syntax of the qualified name is correct. It requires the name of a table, the user name and the path to a geodatabase.
Output parameter values do not need to be qualified because a tool's output is always created by the connected user of the workspace. The following code example shows how a program qualifies table names so it can use tables from a number of users:[Java]
String tableName = gp.qualifyTableName("Census.tgr06000sf1trt", (String) gp.getEnvironmentValue("workspace"));
Structured Query Language (SQL) queries can contain the names of many fields from two or more tables. It is not uncommon for the same field name to exist in separate tables, especially when working with foreign and primary keys. Qualified field names must also be used when a table contains certain field names that are also used by ArcSDE.
To resolve the ambiguity between duplicate names, the field name must be qualified with the table or view name. The QualifyFieldName method allows a database-independent mechanism for creating fully qualified field names, using the table and field name as input.
The following code example ensures that a program always creates a correct SQL statement, regardless of the underlying database type:[Java]
GeoProcessor gp = new GeoProcessor(); gp.setOverwriteOutput(true); gp.setEnvironmentValue("workspace", "C:/temp/census.sde"); //If ArcGIS Desktop is installed, this code looks in the /Application Data/ESRI/ArcCatalog folder //for the appropriate SDE connection files. //gp.setEnvironmentValue("workspace", "Database Connections/census.sde"); String tableName = gp.qualifyTableName("census.tgr06000sf1trt", (String) gp.getEnvironmentValue("workspace")); System.out.println("Here is the tableName " + tableName); MakeFeatureLayer makeFeatureLayer = new MakeFeatureLayer( "census.SanBernardino_Demographics/census.tgr06071trt00", "tractLayer"); gp.execute(makeFeatureLayer, null); AddJoin addJoin = new AddJoin("tractLayer", "STFID", "census.tgr06000sf1trt", "STFID"); gp.execute(addJoin, null); String fieldName = gp.qualifyFieldName("STFID", (String)gp.getEnvironmentValue( "workspace")); //Select a specific tract. SelectLayerByAttribute selectLayerByAttribute = new SelectLayerByAttribute( "tractLayer"); selectLayerByAttribute.setSelectionType("NEW_SELECTION"); selectLayerByAttribute.setWhereClause(fieldName + " = 06071010300"); gp.execute(selectLayerByAttribute, null); //Delete the selected features. DeleteFeatures deleteFeatures = new DeleteFeatures("tractLayer"); gp.execute(deleteFeatures, null);
- ArcGIS Desktop applications, such as ArcMap and ArcCatalog, always present fully qualified feature class, table, and field names. If you are unsure of the table's owner or which tables are accessible, use ArcCatalog to view the contents of the geodatabase.
- Field names, such as Area, Entity, and Len are used by ArcSDE system tables and require programs to fully qualify fields with these names. For more information on ArcSDE field names, see the ArcSDE Administration Guide.