Wednesday, March 28, 2012

Return all fields of database

Hello,

Is it possible to return all the field names of a database. I do not want the data rows. Just a list of fields in the databse.

Thanks

Something like this will do it

Use YourDBName

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

order by 1,3

|||

Thanks for that.

I am trying this

Use CallsAndIncidents

select PROBSUMMARYM1

from information_schema.columns

I have my database as HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1

where PROBSUMMARYM1 is the table name whose fields I want returned . i.e Name,Type ,Level,etc.

I did not understand these 2 lines

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

what should be column_name(many columns), ordinal_position(?), data_type(different data types),information_schema.columns(?)

Thanks for the help Will.

Kiran

|||

... just run this - don't change the SQL

USE HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

and see what you get

or even

USE PROBSUMMARYM1

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

|||

THANKS WILL,

WORKED GREAT

Only change I had to do was from

USE HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

to

USE CallsAndIncidents

select table_name, column_name, ordinal_position, data_type

from information_schema.columns

Thanks a bunch

No comments:

Post a Comment