How to see the data types of all columns in SQL Sever Management System - sql-server

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';

Related

Is there a query for Netezza (Toad Data Point) for finding all tables where a specific field name exists

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%';

Query to find if the list of columns that exists in the SQL Server database

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'

Retrieve column name through db link in Oracle 11g

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'

Count null columns in each row - SQL

I want to count number of columns that are null or = '' in each row in SQL. And group by Row_ID.
Something like this:
SELECT
Row_ID, COUNT(*) AS 'cnt_blankCol'
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
table_catalog = 'db'
AND table_name = 'tblName'
AND COLUMNS IS NULL OR COLUMNS = ''
GROUP BY
Row_ID
ORDER BY
COUNT(*)
Thank you.
Information_Schema tables are metadata tables that contain information about the database objects them selves, it does not contain the actual data from the tables, and it does not contain data aggregates per object.
This can not be done querying information_schema. Perhaps the Op can update the question and give a scenario of the goal of the question.

How to get exact two columns of table(s) from a entair database in SQL server

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.

Resources