如何将SQL Server数据库模式转储为人类可读和可打印的格式?

时间:2022-09-28 07:25:44

I want to generate something like the following:

我想生成如下内容:

LineItems

  • Id
  • Id
  • ItemId
  • ItemId
  • OrderId
  • OrderId
  • Price
  • 价格

Orders

  • Id
  • Id
  • CustomerId
  • CustomerId
  • DateCreated
  • DateCreated

Customers

  • Id
  • Id
  • FirstName
  • 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 个解决方案

#1


4  

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

#2


0  

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.

如果您不介意为此编写一些代码,可以考虑sqlconnector . getschema()方法。您可以在这里找到关于获取数据库模式的更多信息。

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

您需要访问“表”和“列”模式集合,以获得所需的信息。您只能获取非常基本的信息,如表和列名,尽管您可以访问更多的细节。

#1


4  

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

#2


0  

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.

如果您不介意为此编写一些代码,可以考虑sqlconnector . getschema()方法。您可以在这里找到关于获取数据库模式的更多信息。

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

您需要访问“表”和“列”模式集合,以获得所需的信息。您只能获取非常基本的信息,如表和列名,尽管您可以访问更多的细节。