What is the difference between syscat.tabauth and sysibm.systabauth - db2

What is the difference between these two queries:
select * from syscat.tabauth
select * from sysibm.systabauth where tcreator='SYSCAT' and ttname='TABAUTH'
Are they same ?
EDIT:
1. select grantee from sysibm.systabauth where tcreator='SYSCAT' and ttname='TABAUTH' and selectauth='Y'
select grantee from syscat.tabauth where selectauth='Y'
Would there be any difference in the value of these two queries ???
If I change selectauth to 'N' using sysibm.systabauth. Does that reflect in query 2?

The main difference is that one is a table and the other is a readonly view.
Other differences exist, and they can be version specific.
Different permissions can apply also.
When your target database are always on Linux/Unix/Windows , use SYSCAT schema as IBM tries to keep that unchanged even if the underlying objects change between versions (except where new columns get added ). IBM describes the SYSCAT schema here.
The SYSCAT schema contains many views and is relevant for Linux/Unix/Windows versions of Db2-Servers.
The SYSIBM schema contains many tables and is present on both Z/OS and LUW versions of Db2-servers.
So SYSCAT.TABAUTH is only a view on SYSIBM.SYSTABAUTH and you can see the definition of the view in the catalog with a query like this:
"select substr(text,1,4096) from syscat.views where viewschema='SYSCAT' and viewname='TABAUTH'"
You use GRANT and REVOKE statements to alter the contents of the SYSIBM.TABAUTH table directly, other statements like CREATE/DROP/ALTER table can indirectly change its contents.

Related

How to get all external in db2 using a system tables information

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.

postgresql combine data from different schema tables if that schema exists

Need to create a view based on these conditions:
There are several schemas and tables in the db
We will create a union from tables from certain schemas
If the schema don't exist we should skip that schema from our union
It is given that if schema exists the associated table definitely exists, no need to check that.
Query should not give error if any of the schema is not created.
At the time of running query any schema could be missing that is not known until query is run.
So far creating the view using unions is simple enough but I'm not able to figure out what is the best way to include that condition check for schema existence, I'm sorry if this is trivial or duplicate question, any advice or reference could be helpful.
Thanks,
CJ
In postgresql we can use if schema exists:
SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'name';

create (or copy) table schema using postgres_fdw or dblink

I have many tables in different databases and want to bring them to a database.
It seems like I have to create foreign table in the database (where I want to merge them all) with schemas of all the tables.
I am sure, there is a way to automate this (by the way, I am going to use psql command) but I do not know where to start.
what I have found so far is I can use
select * from information_schema.columns
where table_schema = 'public' and table_name = 'mytable'
I added more detail explanation.
I wanted to copy tables from another database
the tables have same column names and data type
using postgres_fdw, I needed to set up a field name and data type for each tables (the table names are also same)
then, I want to union the tables have same name all to have one single table.
for that, I am going to add prefix on table
for instance, mytable in db1, mytable in db2, mytable in db3 as in
db1_mytable, db2_mytable, db3_mytable in my local database.
Thanks to Albe's comment, I managed it and now I need to figure out doing 4th step using psql command.

Fully Qualify MS Access Table

I have an Access query, which references a table: dbo_table2
However, I have moved this table to another database, so I need to fully qualify to restore the links.
SELECT table1.x, table1.y, table2.z
FROM dbo_table1
INNER JOIN dbo_table2
ON (dbo_ID = dbo_ID)
Both tables are being pulled from SQL tables.
In my Access query I have added table2 as a Linked Table.
But I'm unsure of Access syntax. If I was using SQL, I would simply use "newdatabaseDB.dbo.table2".
My question is how can I correctly name the table2 reference by fully qualifying the database and table name.
If you moved your table to another db, just Link that table in your current db. This way you can use just as it was local.
There is another option, using IN:
select * from clients in 'c:\test\mydb.mdb'
Also see https://stackoverflow.com/a/3123395/78522
Cracked it!
By creating a link to an external table in the database where the query was created, Access then treats the table in the queries as if it were local (so no fully qualification needed).

DB2 syscolumns does not return all columns

When running a simple catalog query:
SELECT *
FROM SYSCOLUMNS
I get back only a few hundred rows. This is DB2 7.1 on an AS400. There are dozens of schemas, more than a thousand tables in total. I expect this query to return several thousand rows, not a few hundred. The rows I do get back are only from my test schema and that of one other developer.
I am new to DB2 (20+ years in Oracle), so this is puzzling. The IBM doc says that SELECT is granted to PUBLIC on SYSCOLUMNS, so I should get everything, right? I don't know what the token "SYSCOLUMNS" is pointing to, a view, or local table (which would explain things). In my environment, every query to the database requires SCHEMA_NAME.TABLE_NAME, so this SYSCOLUMNS (with no schema name) is already an exception.
thanks in advance,
db
The answer will depend on what naming mode you're using.
*SQL mode: You qualify tables as SCHEMA.TABLE
*SYS mode: You qualify tables as SCHEMA/TABLE
(Behind the scenes, the schema maps to a library and the table maps to a file.)
In *SQL mode, if you don't specify a schema, the value of CURRENT SCHEMA is used. By default your CURRENT SCHEMA is your user profile, but you can change it like so:
SET CURRENT SCHEMA = SOMELIB
In *SYS mode, if you don't specify a schema, the library list is used to resolve the table name to a particular file.
Anyway, I'm going to guess you're in *SQL naming mode and your current schema is set to your test schema. Querying the un-qualified SYSCOLUMNS will give you the columns in your current schema.
I would try the following, which should widen the scope to all columns on the system:
SELECT * FROM QSYS2.SYSCOLUMNS