tags:

views:

45

answers:

2

I want to generate something like the following:

LineItems

  • Id
  • ItemId
  • OrderId
  • Price

Orders

  • Id
  • CustomerId
  • DateCreated

Customers

  • Id
  • FirstName
  • LastName
  • Email

I don't need all the relationships, the diagram that will never print correctly, the metadata, anything. Just a list of the tables and their columns in a simple text format.

Has anyone done this before? Is there a simple solution?

Thanks,

Kyle

+2  A: 

There are lots of good tools out there to do this for you, but for something quick and dirty you can try something like this:


SELECT t.name, c.name
FROM sys.tables t INNER JOIN sys.columns c
    ON t.object_id = c.object_id

sarme
Thanks. I used this, then pasted into excel, created a pivot table and ended up with EXACTLY what I was looking for.
Kyle West
A: 

If you don't mind writing some code for that, you could consider the SqlConnection.GetSchema() method(s). You can find more information on obtaining the database schema here.

You would need to access the 'Tables' and 'Columns' schema collections to get the information you require. You can pick up only the very basic information like the table and column names, although you have access to a lot more details

alwayslearning