How can I dump my SQL Server Database Schema to a human readable & printable format?
I want to generate something like the following:
LineItems
- Id
- ItemId
- OrderId
- Price
Orders
- Id
- CustomerId
- DateCreated
Customers
- Id
- FirstName
- LastName
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
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
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
精彩评论