How to list all selectable tables with current user in SAP HANA DB - sql

I want to list all tables with current user using sql.
I know there are some way to get privileges, like EFFECTIVE_PRIVILEGES, but it only shows privileges which is granted by GRANT SELECT ~ on [TABLE] to [USERS].

You can query the schema information to get this - there's no SHOW TABLES or equivalent available.
Try:
SELECT TABLE_NAME FROM "SYS"."TABLES" WHERE SCHEMA_NAME='<database_name>'
which works for me.
You can also get Column Names in thsi way from the SYS.COLUMNS view

Related

How to get count of tables present in a particular schema in snowflake?

I am trying to find the count of tables present in CDC schema, I tried with information_schema but the information_schema is empty for me.
The following SQL would give you the required results:
use schema <schemaname>;
show tables;
The result shows the number of tables in the schema.
Note: The information schema in a particular database only displays the objects to which your current role in the session has access.
Please make sure that the role you are using has required access control privileges to view the database objects. If not, if you have access to high privilege roles like SYSADMIN/ACCOUNTADMIN you could use them when viewing metadata information in Snowflake.
You can try querying the INFORMATION_SCHEMA.TABLES View with a query :
select count(distinct TABLE_NAME)
from <database_name>.INFORMATION_SCHEMA.TABLES
where TABLE_CATALOG = <database_name>
and TABLE_SCHEMA = <schema_name>;
Alternatively, you can also use the SHOW TABLES command as follows to get the count.
show tables in schema <DATABASE_NAME>.<SCHEMA_NAME>;
select count(*) from table(result_scan('<last_query_id>'));

DBA readonly account

I had a schema in one oracle DB as ui_prod. I asked my DBA team guys to create exactly same schema like ui_prod but as read only and name it ui_prod_readonly. Usually I will use Oracle SQL developer to connect a DB and query directly with table name like below.
--Connect to ui_prod
select * from table
but why I requested to put owner name infront when query for readonly schema they created for me, as without putting it, I get error table not exist.
--Connect to ui_prod_readonly
select * from ui_prod.table
I have project files which hardcode the sql query with only table names and adding owner name in front will cause many changes and effort. Can anyone explain me on this? or provide me any document/link to read. Thanks
You should look into synonyms, apparently the user you are connecting to the database as is not the owner of the objects. So to view the object you have to prepend the names with the schema name (the owner of the object themselves).
http://www.techonthenet.com/oracle/synonyms.php
CREATE OR REPLACE SYNONYM ui_prod_readonly.synonym_name
FOR ui_prod.object_name
It seems to me that your dbas have not created another set of tables but just granted the existing tables to the user ui_prod_readonly.
When you log in to Oracle, the current schema is the name of the user you used to log in. So if you log in with ui_prod_readonly Oracle checks that schema for the table if you do not qualify it with the owner (=schema).
If you want to change the current schema so that you don't need to fully qualify the tables, you can do that with ALTER SESSION
alter session set current_schema = ui_prod;
Once you have done that, you don't need to fully qualify the table with the owner (=schema).
if you need a user to read the data only
its simple to create new user and grant it only select privilege
you can create user and grant select privilege using
CREATE USER [user] IDENTIFIED BY [your_password];
grant select on table to [user]

How can I list all tables existent in a Database Link (Oracle)?

Basically I have a Database link (Oracle) called mylink.domain, in this link we can access foundation information like name of them members and other general information.
I would like to list all table's name in this link but i don't know how to do that.
Thanks in advance
You can access the all_tables view through the dblink:
select owner, table_name
from all_tables#dblink
order by owner, table_name;
Selecting the content of ALL_TABLES dictionary view will list you all tables your user has access to. Generally, it is not always possible to get a list of tables you dont have permissions for - they just do not show up. If your user has the SELECT ANY DICTIONARY priviledge, you can select the content of DBA_TABLES, which will always list all tables existing in the database.
select table_name from all_tables#dblinkname;
This shows all tables your linked user has access to.
Where I got the answer from

in oracle SQL developer How do I display list of all tables from current user/schema

I m working in oracle SQL developer database where I want to display list of all tables from current user/schema
You see the list of tables as owned by the current schema user in the Tree view of the connection under "tables". If you login as sys, then you see sys owned (of course).
If you want to see the schema of a different user, you need to have select permissions on the tables (and maybe some more in SQL Developer). Then you can see the tables of the other schema under <Connection>/Other Users/<User>/Tables/*.
If you don't see tables there, then you need to check for Synonyms, global synonyms or views. Finally if none of them are showing the expected tables (and you are aure you logged into the correct instance and CDB) then there might be a different active default schema for your user active after logon (typical case of a logon trigger). In this case the statement from before applies: look under the user who owns them.
SQL Developer internally used the ALL_* and USER_ system views. For example your tables owned by you: select TABLE_NAME from user_tables. More complete description of that is here.

Getting all tables from an oracle database

I'm trying to retrieve a list of tables from an Oracle connection. I'm not very familiar with Oracle terminology and thus, having hard time finding the information I need.
Right now I can use Microsoft Access to connect via ODBC and it pops up with a "Link Tables" dialog that lists all tables, not just the ones I "own". None of the queries I've tried so far, give me this data.
I'm trying "SELECT * FROM all_tables" but that doesn't show me the right data.
ALL_TABLES will show you all the tables that you have access to SELECT from. DBA_TABLES will show you all the tables that exist in the database though you'll need an additional privilege grant to be able to query the DBA* data dictionary objects.
Try select * from all_tables, that should do what you want.
It can be.. (If user has dba role)
select * from dba_tables
SELECT owner, table_name
FROM all_tables
You can also try
SELECT * FROM USER_TABLES
It will return list of tables owned by your user.
SELECT * FROM TAB; that will show you all the table and views