I have created a table, but is not listed on DataStudio 4101(tables node)
I can insert data by sql commands and drop/create the table, but can not find it on the server Database Node, under tables.
Other tables are displayed, but not the new ones I made.
IF you are using DB2 for i, with "system naming" mode, then your tables may have been created in schema QGPL (the General Purpose Library) by default. Your DB2 session would find them by using its "library list", similar to a path list.
Related
I need to get complete list of external tables in db2 database. I have defined schema called DB2INST1. How to get complete list of external tables information using system tables?
The information lives in syscat.tables (documentation here) for Db2-LUW databases that support external tables, which have their PROPERTY column with value Y in position 27 of that column.
Example query returns the fully qualified name of external tables:
select trim(tabschema)||'.'||rtrim(tabname)
from syscat.tables
where substr(property,27,1)='Y'
with ur;
In general, the best and most reliable way to retrieve all information and to recreate the DDL statements for tables is to use the db2look tool. If you want to extract the metadata on your own, there are some catalog views to start with:
SYSCAT.TABLES holds the table information. Look for the PROPERTY column and check there if it is an external table.
SYSCAT.COLUMNS has the basic column information. But there are more related tables depending on types and attributes.
SYSCAT.EXTERNALTABLEOPTIONS shows the actual options for an external table, the things in addition to what makes a regular table.
There are many more tables to hold table properties, depending on the complexity of the table and column definitions.
For a long time I have been working only with Oracle Databases and I haven't had much contact with PostgreSQL.
So now, I have a few questions for people who are closer to Postgres.
Is it possible to create a connection from Postgres to Oracle (oracle_fdw?) and perform selects on views in a different schema than the one you connected to?
Is it possible to create a connection from Postgres to Oracle (oracle_fdw?) and perform inserts on tables in the same schema as the one you connected to?
Ad 1:
Yes, certainly. Just define the foreign table as
CREATE FOREIGN TABLE view_1_r (...) SERVER ...
OPTIONS (table 'VIEW_1', schema 'USERB');
Ad 2:
Yes, certainly. Just define a foreign table on the Oracle table and insert into it. Note that bulk inserts work, but won't perform well, since there will be a round trip between PostgreSQL and Oracle for each row inserted.
Both questions indicate a general confusion between a) the Oracle user that you use to establish the connection and b) the schema of the table or view that you want to access. These things are independent: The latter is determined by the schema option of the foreign table definition, while the former is determined by the user mapping.
How to get the name of the schema, tables and primary keys?
How to know his authorizations?
The only information I have is obtained by the command below:
db2 => connect
Database Connection Information
Database server = DB2/AIX64 11.1.3.3
SQL authorization ID = mkrugger
Local database alias = DBRCF
You can use the command line (interactive command line processor), if you want, but if you are starting out then it is easier to use a GUI tool.
Example free GUI, IBM Data Studio, and there are many more (any GUI that works with JDBC should work with Db2 on Linux/Unix/Windows). These are easy to find online and download if you are permitted.
To use the Db2 command-line (clp) which is what you show in your question,
Example command lines:
list tables for all
list tables for user
list tables for schema ...
describe table ...
describe indexes for table ...
Reference for LIST TABLES command
You can also use plain SQL to read the catalog views, which describes the schemas, tables, primary keys as a series of views.
Look in the online free documentation for details of views like SYSCAT.TABLES, SYSCAT.COLUMNS , SYSCAT.INDEXES and hundreds of other views.
Depending on which Db2 product is installed locally, there are a range of other command-line based tools. One in particular is db2look which lets you extract all of the DDL of the database (or a subset of it) into a plain text file if you prefer that.
Using the answer from the Oracle SQL Developer and PostgreSQL question, I have connected Oracle SQL Developer (4.1.3.20) to my PostgreSQL (9.1.20) database.
But only a weird subset of the objects in the database appears in the SQL Developer "Connections" browser. Specifically:
The public schema (which is the default PG user data schema) doesn't show up. But if I create another schema (e.g. one named schema1 in the screen shots below), the schema does show up.
Within a visible schema (schema1), tables, views, their columns, and their data are visible. So are triggers. There are headings for indexes and functions, but the functions, trigger functions, and indexes that exist are not visible. There aren't even headings for sequences, domains, catalogs, and extensions. Refreshing the display of the schema evokes 'ERROR: syntax error at or near ""INDEX_NAME"" Position: 99'.
Here it is in screen shots:
This is the database as shown in the PgAdminIII object browser
This is the database as shown in the Oracle object browser - also showing the above-mentioned error message
Another weirdness: I can open a SQL window in the Oracle tool and execute both DML (select, insert, etc) and DDL (create table, create function, etc), even in the (invisible) public schema. I can even query the PG catalogs (information_schema and pg_catalog).
So the question is: How can I make the missing objects (most importantly, the public schema) visible in SQL Developer?
~ Thanks, Ken
With SQLdeveloper 4.2, public schema is back ;o)
I am developing a windows application and using Postgres as backend database. At some point in my application i am dynamically creating table e.g Table1, then Table2 and so on. In this way i have many dynamic table in my database. Now i provide a button "Clean Database", so i need to remove all those dynamic tables using SQL query. Should some one guide me how to write SQL Query that automatically delete all such tables?
You should just be able to say
DROP TABLE {tablename}
for each dynamically created table. Try that and see if it works.