I have just started using and learning SQL server
i am using a database wcm_staging (so tables in this database are like this - wcm_staging.dbo.cust_id, and there are many tables like this), I need to check the column names (variable names) in all the tables in this particular database.
Can some one help please about how to do it?
Many thanks,
Best
Ritika
This will list out all the table names and column names with data tyes
USE DATABASE NAME
GO
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='TABLE NAME'
SELECT
OBJECT_NAME(object_id) AS [Table Name],
name AS [Column Name]
FROM sys.columns
ORDER BY 1
Related
Request
I want to list all the table names in a schema in association with the list of that table attributes. I'm using DBeaver, but I can download other software if it works. I don't mind about the output data extension: txt, excel, csv etc., but I'm not searching for an ER diagram.
Example
If the database schema contains these three tables
TABLE_A
ATTRIBUTE_A_1
ATTRIBUTE_A_2
ATTRIBUTE_A_3
TABLE_B
ATTRIBUTE_B_1
TABLE_C
ATTRIBUTE_C_1
ATTRIBUTE_C_2
I want to extract something like this:
TABLE_A
ATTRIBUTE_A_1
ATTRIBUTE_A_2
ATTRIBUTE_A_3
TABLE_B
ATTRIBUTE_B_1
TABLE_C
ATTRIBUTE_C_1
ATTRIBUTE_C_2
Thanks in advance!
I've find out that, in Oracle, it's possible to list all the columns visible by the user who executes this query:
SELECT
TABLE_NAME,
COLUMN_NAME
FROM
ALL_TAB_COLUMNS
ORDER BY
TABLE_NAME ASC
DBeaver doesn't support "info" and "describe" commands as SQLDeveloper does. You can use a query like "SELECT ... FROM user_tab_columns".
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 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
Here is details
In sybase, I have a table "abc" having 5 fields(name, roll, address, desc,path). If i would use 'sp_help tablename' then i can see all properties of all fields how i can get properties of a particular field i.e. roll or any one field and their properties using sql or pl/sql.
As we know that we can not use any parameters in sp_help so is there any way to to get the properties of a field, (pl/sql or sql)?
Thanks in advance
sp_help tablename
This depends on what specific properties you are looking for. Assuming you are looking for Table, Column, Datatype, Datatype Length - you have to join sysobjects, syscolumns, and systypes
use YOURDB
go
select o.name, c.name, t.usertype, c.length
from
sysobject o,
syscolumns c,
systypes t
where o.id = c.id
and c.usertype = t.usertype
and o.name like "YOUR_TABLE"
and c.name like "YOUR_COLUMN"
go
If you want more than that, you'll have to bring in other columns and/or tables into the query like sysdepends, sysdefaults or sysconstraints
More information about the system tables can be found here:
Sybase ASE Reference Manual: Tables > System Tables
And the system table diagram, which shows the column mappings can be found here:
http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc70204.1550/pdf/a155pst.pdf
Also, FYI - Sybase uses T-SQL (like SQL Server), not pl/sql.