BigQuery: get table description using INFORMATION_SCHEMA - google-bigquery

Is it possible go get a BigQuery table's description from the INFORMATION_SCHEMA ?

You can use INFORMATION_SCHEMA.TABLE_OPTIONS view with option_name = 'desciption'
SELECT *
FROM `bigquery-public-data.chicago_crime`.INFORMATION_SCHEMA.TABLE_OPTIONS
WHERE option_name = 'description'
AND table_name = 'crime';
Query results
option_value shows a table description.
https://cloud.google.com/bigquery/docs/information-schema-table-options

Related

Query to find the column names of a table using BIgquery

I am working on project_name='Alpha' and dataset_name = 'Beta' and this dataset contains numerous tables. I want to get table details i.e, columns of a particular table i.e, table_name = 'Gamma'
To retrieve meta data information. you can use INFORMATION_SCHEMA.
Try with below query..
SELECT column_name FROM `project_name.dataset_name.INFORMATION_SCHEMA.COLUMNS`
WHERE table_name = <'Table Name'>;
For your solution, You can use INFORMATION_SCHEMA.COLUMNS
First, try with below:
SELECT * FROM Alpha.Beta.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Gamma' ;
Then you can select the details you want, only for the column name you can use below;
SELECT column_name FROM Alpha.Beta.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Gamma' ORDER BY ordinal_position asc ;
Please do let me know if it doesn't work out but flag it as an answer if it works.
EDIT: if it didn't work, can you please try putting Alpha.Beta.INFORMATION_SCHEMA.COLUMNS between escape character

How to display a list sqlite database tables, except table sqlite_sequence?

Doing so
select name from sqlite_master where type='table'
but I need to display all tables except sqlite_sequence.
What's wrong with the following SQL?
select name from sqlite_master where type = 'table' and name <> 'sqlite_sequence'

Description of Tables in DB2 based on dataype

How can we see the details of columns based on data type for a table in DB2 .
Like suppose I have a table with 100 columns but I want to see about the columns of data type timestamp only. How can I achieve this ?
If you're on Linux/Unix/Windows DB2, then you can use the SYSCAT.COLUMNS catalog view:
SELECT *
FROM SYSCAT.COLUMNS
WHERE TABSCHEMA= 'YOUR_SCHEMA'
AND TABNAME = 'YOUR_TABLE'
AND TYPENAME = 'TIMESTAMP'
Replacing YOUR_SCHEMA and YOUR_TABLE, obviously. If you're on mainframe DB2, then you will use the similar SYSIBM.SYSCOLUMNS catalog view:
SELECT *
FROM SYSIBM.SYSCOLUMNS
WHERE TBCREATOR='YOUR_SCHEMA'
AND TBNAME ='YOUR_TABLE'
AND COLTYPE ='TIMESTMP'

The cursor SQL_CURLH200C1 is not in a prepared state

Can anyone provide an explanation for the following:
select * from 'table' as t where t.identifier = 1234567890
Returns:
THE SQL STATEMENT IS NOT SUPPORTED. SQLCODE=-142, SQLSTATE=42612
select * from 'table' as t where t.identifier = 12345
Returns:
1 row(s)
Identifier is defined as PIC S9(11) COMP-3, DB2
'table' is a string literal with the value table therefor it cannot be used as a table name.
If your table is really called table, then you need to use this:
select * from "TABLE"
or
select * from "table"
depending on how you created that table named table.

How can I find all indexes available on a table in DB2

How to find all indexes available on table in db2?
db2 "select * from syscat.indexes where tabname = 'your table name here' \
and tabschema = 'your schema name here'"
You can also execute:
DESCRIBE INDEXES FOR TABLE SCHEMA.TABLE SHOW DETAIL
You can get the details of indexes with the below command.
describe indexes for table schemaname.tablename show detail
To see all indexes :-
select * from user_objects
where object_type='INDEX'
To see index and its columns on table :
select * from USER_IND_COLUMNS where TABLE_NAME='my_table'
This depends upon which version of DB2 you are using.
We have v7r1m0 and the following query works quite well.
WITH IndexCTE (Schema, Table, Unique, Name, Type, Columns) AS
(SELECT i.table_schema, i.Table_Name, i.Is_Unique,
s.Index_Name, s.Index_Type, s.column_names
FROM qsys2.SysIndexes i
INNER JOIN qsys2.SysTableIndexStat s
ON i.table_schema = s.table_schema
and i.table_name = s.table_name
and i.index_name = s.index_name)
SELECT *
FROM IndexCTE
WHERE schema = 'LIBDEK'
AND table = 'ECOMROUT'
If you're not familiar with CTE's they are worth getting to know. Our AS400 naming conventions are awful so I've been using CTE's to normalize field names. I ended up making a library of CTE's and have it automatically append to the top of all my queries.
For checking the indexes of a table on IBM Db2 on Cloud (previously DashDb) the following query should do it:
SELECT * FROM SYSCAT.INDEXES WHERE TABNAME = 'my_tablename' AND TABSCHEMA = 'my_table_schema'
You can use also check by index name:
SELECT COUNT(*) FROM SYSCAT.INDEXES WHERE TABNAME = 'my_tablename' AND TABSCHEMA = 'my_table_schema' AND INDNAME='index_name'
The same result can be achieved by using SYSIBM.SYSINDEXES. However, this table is not referenced directly on the product documentation page.
SELECT COUNT(*) FROM SYSIBM.SYSINDEXES WHERE TBNAME = 'my_tablename' AND TBCREATOR = 'my_table_schema' AND NAME='my_index_name'
See SYSCAT.INDEXES catalog view.
One more way is to generate the DDL of the table.
It will give you the complete description of table including index on it.
Just right click on table and click on generate DDL/Scripts.
Works on most of the database.