Discovering Schemas
The following sections show how to obtain schema information.
List Tables and Views
You can use the sqlTables function to discover what tables and views are available through the driver. This returns results in a data frame like a query would.
results <- sqlTables(cnx) for (row in 1:nrow(results)) { cat(paste("Catalog: ", results[row,]$TABLE_CAT, ", Schema: ", results[row,]$TABLE_SCHEM, ", Table: ", results[row,]$TABLE_NAME, ", Type: ", results[row,]$TABLE_TYPE, "\n")) }
You can use the sqlColumns function to discover what columns are available on a table or view.
results <- sqlColumns(cnx, sqtable = "Resources") for (row in 1:nrow(results)) { cat(paste("Name: ", results[row,]$COLUMN_NAME, ", Type: ", results[row,]$DATA_TYPE, ", Length: ", results[row,]$COLUMN_SIZE, ", Precision: ", results[row,]$DECIMAL_DIGITS, ", Nullable: ", results[row,]$IS_NULLABLE, "\n") }