0

I have tried this query, but it returns an error :

Select DATA_TYPE 
From INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Customers' AND
COLUMN_NAME IN (Select *
From INFORMATION_SCHEMA.COLUMNS
Where TABLE_NAME = 'Customers');

Error :

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

3 Answers 3

1

Just use

Select COLUMN_NAME , DATA_TYPE 
From INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Customers'

BTW if you use the in clause, then select only a single column in the subquery and not all

where COLUMN_NAME IN (Select col from table)

and not

where COLUMN_NAME IN (Select * from table)
Sign up to request clarification or add additional context in comments.

2 Comments

How would I display Column Name next to column data type?
Add it to the list after select. I updated the answer. That is very basic SQL. Please take a tutorial to get used to the basic stuff
1

I would be careful with collation and use:

Select DATA_TYPE 
From INFORMATION_SCHEMA.COLUMNS
WHERE lower(TABLE_NAME) = 'customers';

Comments

0
select DATA_TYPE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Customers'

Or a better solution would be

SELECT  c.name AS [Column Name],
       t.Name AS [Data type]
FROM sys.columns c
INNER JOIN  sys.types t ON c.user_type_id = t.user_type_id
WHERE c.object_id = OBJECT_ID('Customers')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.