I want to retrieve column names from a table through a db link but I'm not able to do it...
Although this query is working
SELECT *
FROM myTableName#myDbLink;
the following one is not:
SELECT column_name
FROM all_tab_columns#myDbLink
WHERE table_name = 'myTableName'
What's the correct way of retrieving the column names?
CaSE mATterS.
In Oracle, table names are - by default - in UPPERCASE, so - try with
SELECT column_name
FROM all_tab_columns#myDbLink
WHERE table_name = 'MYTABLENAME'
Related
I have the following query which works perfectly when searching for tables that contain a specific field name that I am looking for in an Oracle database
however it does not work in Netezza (Data Mart) when using the Toad Data point tool. Can someone let me know if there is anything similar to the query below which would work in a Netezza Data Mart environment.
Select DISTINCT TABLE_NAME, COLUMN_NAME
FROM ALL_TAB_COLUMNS
WHERE COLUMN NAME LIKE '%EXANOKE_FIELD_NAME%'
Select DISTINCT TABLE_NAME, COLUMN_NAME
FROM COLUMNS
WHERE COLUMN_NAME LIKE '%EXANOKE_FIELD_NAME%';
I have a list of columns. I want to build a query to find if the columns exists in the ServicingDB database.
We can also use the filter for the tables starting with abcd (example).
Thanks in advance.
You can use the below query to find out the Specific column along with database name, table name etc.
select * from information_schema.columns where column_name = 'yourColumnName'
I could not find answer to this question, despite it being very basic. How do I know whats the data type of all columns in SQL Server management System?
Col1 Col2 Col3 and so on
I wish to know the datatypes of each column in say Table1 where Table1 is the name of my table .
There are couple of options to see the data types of columns of the desired table -
Option 1
sp_help <tableName> e.g. sp_help Table1
Option 2
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Table1'
Option 3
Expand the Tables
Expand the desired table
Expand the columns
There are many several way to do this, one of them is to use schema :
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'Table1' or
COLUMN_Name = 'col1';
There are two tables - Entity table and Account table. Entity table having EntityID and Account table having AccountID. There is a 3rd table EntityAccountAssociation which contains both EntityID and AccountID. - This I know.
My scenario is; suppose in a product support, I do not know about this 3rd table (and no one is there to tell me) , then, is there any query to find out this 3rd table to get the relationship in a huge database with 100s of table?
For Example: In that query, I will pass these two column name as parameter and it will show me on which particular table these two columns exists.
Please help and let me know. Thanks.
If all you're looking for is a query that returns table(s) with both columns, this would do:
-- DECLARE #col1 NVARCHAR(255) = 'X', #col2 NVARCHAR(255) = 'Y'
SELECT TABLE_SCHEMA + '.' + TABLE_NAME TablesContainingBoth
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN (#col1, #col2)
GROUP BY TABLE_SCHEMA + '.' + TABLE_NAME
HAVING COUNT(*) > 1
If only one table had both columns, it would return one result.
I have a sql server database which contains 7000 tables and every table ends with a date. I need to find out all the tables of a particular date.
I have the table names as follows:
HouseKeeping_Stage1_12_6_14,
HouseKeeping_Stage1_13_6_14,
HouseKeeping_Stage1_14_6_14,
HouseKeeping_Stage2_12_6_14,
HouseKeeping_Stage2_13_6_14
I want to find out all the records which are associated with the date 12_6_14.
Please let me know how to write the query.
Using SSMS Object Explorer, right-click on the Tables node and select Filter-->Filter Settings. The list will be filtered accordingly.
Alternatively, you can query the catalog or INFORMATION_SCHEMA views:
SELECT
OBJECT_SCHEMA_NAME(object_id) AS schema_name
, name
FROM sys.tables
WHERE name LIKE '%[_]13[_]6[_]14%';
SELECT
TABLE_SCHEMA
, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%[_]13[_]6[_]14%';
This should do the trick:
SELECT * FROM information_schema.tables
where table_name like '%12_6_14%'
Here is an example: http://sqlfiddle.com/#!6/304bd/1/0