I'm using this query to shows table from a schema in h2, but it's not working
enter image description here
The SHOW command does not implement complex filtering conditions. However, you can run a simple SELECT to get your tables:
select table_name
from information_schema.tables
where table_schema = 'PUBLIC' -- your schema
and table_type = 'TABLE'
and table_name like '%RU%' -- your custom filtering condition
Related
I am doing a procedure in the oracle database that has the function of performing a kind of inventory of the objects of the database.
Basically I must get the DDL of objects of type table.
For this, I am using queries from the bank itself as:
select * from user_objects;
select * from user_constraints;
select * from user_source;
My inventory must contain the following information:
Inventory information here.
How do I get the DDL command from objects without using the function:
dbms_metadata.get_ddl();
and no other ready functions from the metadata library.
I have also tried this:
SELECT
(CASE WHEN line = 1 THEN 'create or replace ' || text ELSE text END) texto
FROM user_source
WHERE NAME = '....'
ORDER BY line
but this command does not get the ddl of table objects.
For getting the DDL of views, it's very easy:
SELECT VIEW_NAME, TEXT FROM ALL_VIEWS;
If you want it to return just the text of a particular view, then do:
SELECT TEXT FROM ALL_VIEWS
WHERE VIEW_NAME LIKE '[name_of_view]';
Getting the DDL for tables is more cumbersome, but can be done by querying the data from several system views:
ALL_TABLES ALL_TAB_COLUMNS ALL_COL_COMMENTS
ALL_CONSTRAINTS ALL_CONS_COLUMNS ALL_INDEXES
ALL_IND_COMMENTS
For example, if you wanted to get all column names and their data types for TABLE1, you would do:
SELECT COLUMN_NAME, DATA_TYPE FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME LIKE 'TABLE1';
To get a list of all constraints on a table, the query is:
SELECT * FROM ALL_CONSTRAINTS
WHERE TABLE_NAME LIKE 'TABLE1';
To get a full table definition takes a fairly good understanding of how to use these system views. A very helpful page for this can be found here: 6 Useful Oracle Data Dictionary Queries Every DBA Should Have
I am facing an issue when fetching column names for the particular table
I wrote the following query
SELECT column_name
FROM all_tab_cols
WHERE Table_name like 'tabelname';
But what happen in table have 54 columns but when I run that code 224 columns coming. I don't known why.
Assuming Oracle, not SQL Server.
all_tabl_cols shows columns from all tables the current user has access to, not those owned by the current user. If the same table exists in different schema, all of them will be shown.
The LIKE operator makes no sense if you don't use a wildcard pattern with it. It would be cleaner to use Table_name = 'tabelname' instead.
Oracle stores table names in UPPERCASE (unless you created them using those dreaded double quotes). And string comparison is case-sensitive in Oracle. So you must compare the the content of the column table_name with an uppercase name-
You can either use user_tab_cols instead of all_tab_cols
SELECT column_name
FROM user_tab_cols
WHERE table_name = 'THE_TABLE';
or you need to specify the owner:
SELECT column_name
FROM all_tab_cols
WHERE table_name = 'THE_TABLE'
AND owner = user;
SELECT column_name
FROM all_tab_cols
WHERE table_name = 'VERIFICATION'
AND owner = 'APPDB'
AND column_name NOT IN ( 'password', 'version', 'id' )
I have this query below. This query finds on database if that particular table is exists in the database. My question is, by using INFORMATION_SCHEMA.TABLES, is it going to find that table name to the other database? Or in just particular database where you are connected???
select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = N'WebServiceCredentials'
As per the MSDN:
Returns one row for each table in the current database for which the
current user has permissions
You can view all the tables for all databases, but not using INFORMATION_SCHEMA.TABLES
You can using system tables.
You can run this query:
sp_msforeachdb 'select "?" AS dbname, * from [?].sys.tables'
Is there a query I can write to search all the column names for a particular database in Netezza?
Within the same database you can use the following query:
select *
from _v_odbc_columns1
where column_name like '%columnname%'
or a less Netezza specific query
select *
from information_schema.columns
where column_name like '%columnname%'
The important catalog views in netezza system are listed below
_V_USER: the user view gives information about the users in the netezza system.
_V_TABLE: the table view contains the list of tables created in the netezza performance system.
_V_RELATION_COLUMN: the relation column system catalog view contains the columns available in a table.
_V_TABLE_INDEX: this system catalog contains the information about the
indexes created on table. netezza does not support creating indexes on a table as of now.
_V_OBJECTS: lists the different objects like tables, view, functions etc. available in the netezza.
Example:
SELECT *
FROM _V_RELATION_COLUMN
WHERE
ATTNAME like '%GEO%' --SPECIFY COLUMN NAME
AND type = 'TABLE'
You would access something similar to an information_schema.
Column Name, %COW%', would use % as a wildcard...gathering any column that has 'COW' in the name
SELECT *
FROM _V_SYS_COLUMNS
WHERE
COLUMN_NAME like '%COW%'
AND TABLE_SCHEMA = 'DEV'
ORDER BY TABLE_NAME
;
Is there an HSQLDB equivalent for the MYSQL SHOW COLUMNS from TABLE command?
HSQLDB does not have separate commands for showing tables, columns or other database objects.
You use SELECT * FROM INFORMATION_SCHEMA.COLUMNS and various other tables in the INFORMATION_SCHEMA for such purposes.
http://hsqldb.org/doc/2.0/guide/databaseobjects-chapt.html#dbc_information_schema
This is the query that you need.
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '<your schema>' AND TABLE_NAME = '<name table or view>';