获取表的架构 [英] Getting the schema for a table

查看:88
本文介绍了获取表的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个SQLConnection对象,如何为单个表获取模式?

Given an SQLConnection object how can you get a schema for a single table?

前几天我在尝试这种方法,但似乎能够获取该模式从我通过运行查询获得的数据集中获取,但是我从连接中可以获得的所有架构信息似乎都与可用的表有关,而不是与表上的实际详细信息有关。

I was trying this the other day and I seemed to be able to get the schema from a DataSet which I'd gotten from running a query, but all the schema info I could get from the connection seemed to be related to what tables were available and not the actual details on the tables.

我确定有一种简单的方法可以做到这一点。

I'm sure there is a simple way to do this.

推荐答案

我认为访问模式从查询(通过GetSchemaTable)中获取数据是唯一的方法。
如果您只对模式感兴趣,则可以运行不返回任何行(从表中的*为1 = 2的表中选择*)的查询。

I think accessing the schema from the query (via GetSchemaTable) is the only way to do it. You can run a query which returns no rows (select * from table where 1=2) if the schema is all you're interested in.

您应该使用KeyInfo CommandBehaviour来执行源查询,否则,并非所有返回的信息都被保证是正确的

You should use the KeyInfo CommandBehaviour to execute the source query, as otherwise not all the information returned is guaranteed to be accurate

Command.ExecuteReader(CommandBehavior.KeyInfo)

这篇关于获取表的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆