Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A list of all the fields. 1

Status
Not open for further replies.

brianpercival

Programmer
Jun 13, 2005
63
US
Is there anyway in ms sql where I canprint the table structure? I have tables with like 160 fields, don't have the queries that created them and am having a hard time to constantly shift windows to look at the required fields while coding. How can I print a hardcopy of the table structure?

regards,
Brian
 
Run the following query in Query Analyzer. You can copy/paste the results in to Excel, format the output to your needs, and then print.

Code:
Select * from Information_Schema.Columns Order By TABLE_NAME, ORDINAL_POSITION

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
gmmastros, thanks for your response.

My table name is "table1" in database "database1". I tried running

select * from Information_Schema.Columns Order By table1, ORDINAL_POSITION

It comes up saying invalid column name "table1". What am I doing wrong?

regards,
Brian
 
try running the code EXACTLY as shown. TABLE_NAME is a field returned by the query. It will show all tables and their columns (fields). If you want just a single table, then you can run this...

Code:
Select * from Information_Schema.Columns 
Where Table_Name = 'Table1'
Order By TABLE_NAME, ORDINAL_POSITION

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
TABLE_NAME is the name of a column in the Information_Schema.Columns table

if you want to show the layout of just one table, use a WHERE clause --
Code:
select * 
  from Information_Schema.Columns 
 where TABLE_NAME = 'table1'
order 
    by ORDINAL_POSITION
:)

r937.com | rudy.ca
 
r937, nice query though. [wink]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top