2

I am looking for an sql script which can select all fields in a database which are of a particualr datatype.

I have looked all over stack overflow and various pages i have found in google but yet no avail!

Maybe I am looking in the wrong places.

Any ideas?

2
  • Interesting one, my first question would have to be why are you trying to do this? Perhaps there is a better way.. Commented Jul 24, 2013 at 13:37
  • I have to manage 4 identical SQL servers which are all out of sync and I need to convert all datetime2 datatypes to datetime. I have the rest of the sql code which will do the conversion, the answer below is perfect. Feel a bit embarrassed its so simple... Commented Jul 24, 2013 at 13:48

3 Answers 3

3

This will give you list of all the fields to of perticular data type in a data base with table name may be you can work around this.

SELECT * FROM .INFORMATION_SCHEMA.COLUMNS where DATA_TYPE=''

Regards

Ashutosh Arya

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I thought it was going to be more complicated than that!
Welcome!You can find other tables unders information_Schema, if you wanna try something more. :)
1

Try this

USE DatabaseName;
SELECT TABLE_CATALOG
    ,TABLE_SCHEMA
    ,TABLE_NAME
    ,COLUMN_NAME
    ,DATA_TYPE 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE DATA_TYPE LIKE 'varchar' --Or other Data Type

Comments

0

In MySQL, you can try select by type.

SELECT COLUMN_NAME
FROM information_schema.COLUMNS
WHERE COLUMN_TYPE = 'datetime';

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.