HANA list / show tables SQL Command - sql

How to show / list all tables in SAP HANA via SQL?

SAP HANA provides a database catalog (just like most other DBMS) via system tables like TABLES, VIEWS, USERS, etc. ...
These are the ANSI-92 compliant metadata views.
Instead of the INFORMATION_SCHEMA SAP HANA provides these views in the PUBLIC schema (again, like other DBMS do that).
Example:
select * from tables
select * from public.tables
The M_TABLES provides information about the runtime objects that represent tables.

SELECT TABLE_NAME FROM SYS.M_TABLES

To view tables from a specific schema :
select * from SYS.M_TABLES where SCHEMA_NAME ='<your schema name goes here>'

It is my understanding that HANA is compatible with ANSI SQL. If this is actually the case, the following should work:
SELECT * FROM INFORMATION_SCHEMA.TABLES
Of course, I don't have access to a hana instance to prove this.
CORRECTION:
After looking at some documentation, it looks like SAP supports this type of thing through a SYS schema:
https://help.sap.com/saphelp_hanaplatform/helpdata/en/20/cbb10c75191014b47ba845bfe499fe/content.htm?frameset=/en/2e/1ef8
So, I think you would actually select from:
SYS.M_TABLES

Related

how to obtain a list of schemas in intersystems cache?

I'm connecting to a Caché database using the ODBC driver, and I want to do a query to obtain a list of schemas. In Microsoft SQL Server I can use a query like this:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
How can I do this in Caché? I'm also using ADO.NET schema collections, but the schemas don't seem to be available there.
The schema %dictionary has the tables you are looking for. You could select from %dictionary.compiledclass

postgresql list all table fields information within a server

i'm in need to create VIEWS in postresql 9, to mimic oracle's col table,
basically it should display ALL table fields information from ALL table and ALL database on that server.
Can someone please point me a way? thanks.
Unlike Oracle, PostgreSQL implements the ANSI information_schema.
So Oracle's ALL_TAB_COLUMNS view corresponds to information_schema.columns
But this is only restricted to the current database. It is not possible to get this information for all databases - which is the same for Oracle, ALL_TAB_COLUMNS only shows the columns for the current database (=instance)
More details about the information_schema can be found in the manual
http://www.postgresql.org/docs/current/static/information-schema.html
I don't think is possible to get metadata information from a different database of that you've working right now.
To extract metadata from the current database, take a look here: http://www.alberton.info/postgresql_meta_info.html

Utility to create sql statements

This is a question about Sql generation, not sql creating sql nor ORM.
Is their any cross database tools that will enable the creation of insert statements, e.g. for all the tables in particular schema or namespace. Say the namespace/schema is Aqua in Sql Server 2008, and your utility comes along and generates all possible insert statements for that namespace/schema. And it works on Oracle/MySql/Postgres/db2 etc.
Thanks.
Bob
ANSI SQL provides for a standard set of views under the schema INFORMATION_SCHEMA to provide metadata for just this purpose.
For generating simple table insert statement templates, all the information you really need to generate an insert statement for a given table is to execute this query:
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG = <my-db-name>
and TABLE_SCHEMA = <table-owner-schema>
and TABLE_NAME = <table-name>
order by ORDINAL_POSITION
in any database that supports the ANSI information schema views. That will give you one row for every column in the specified table, in the expected sequence.
Outside of the above, since no two vendors support the set of system tables with metadata, your pretty much SOL for a cross-database solution. And sadly, I don't believe the Oracle supports the ANSI information schema views.
Though you might look at Red Gate's product family: http://www.red-gate.com/

Listing all tables in a database

Is there a SQL command that will list all the tables in a database and which is provider independent (works on MSSQLServer, Oracle, MySQL)?
The closest option is to query the INFORMATION_SCHEMA for tables.
SELECT *
FROM INFORMATION_SCHEMA.Tables
WHERE table_schema = 'mydatabase';
The INFORMATION_SCHEMA is part of standard SQL, but not all vendors support it. As far as I know, the only RDBMS vendors that support it are:
MySQL
PostgreSQL
Microsoft SQL Server 2000/2005/2008
Some brands of database, e.g. Oracle, IBM DB2, Firebird, Derby, etc. have similar "catalog" views that give you an interface where you can query metadata on the system. But the names of the views, the columns they contain, and their relationships don't match the ANSI SQL standard for INFORMATION_SCHEMA. In other words, similar information is available, but the query you would use to get that information is different.
(footnote: the catalog views in IBM DB2 UDB for System i are different from the catalog views in IBM DB2 UDB for Windows/*NIX -- so much for the Universal in UDB!)
Some other brands (e.g. SQLite) don't offer any queriable interface for metadata at all.
No. They all love doing it their own little way.
No, the SQL standard does not constrain where the table names are listed (if at all), so you'll have to perform different statements (typically SELECT statements on specially named tables) depending on the SQL engine you're dealing with.
If you are OK with using a non-SQL approach and you have an ODBC driver for the database and it implements the SQLTables entry-point, you possibly might get the information you want!
pjjH
details on the API at:
http://msdn.microsoft.com/en-us/library/ms711831.aspx

sql select thru multiple postgres databases

is there a way to create a select statement that would retrieve data from multiple database in postgre?
i was thinking it would be something like this:
select * from dbname1.table1, dbname2.table2 where dbname1.table1.column1 = dbname2.table2.column1
Have a look at the "dblink" contrib module.
OTOH it's possible that you treat the databases in a PostgreSQL cluster as equivalent to the databases in... let's say MySQL. Which is incorrect - the PostgreSQL databases contain schemas and those are the equivalent of the databases in MySQL.
From here:
It is not possible to access more than
one database per connection.
Update: but see Milen's answer.