How to easily obtain database architecture Information

Source: Internet
Author: User

During database operations, we often need to read the architecture information from the database. I used to use SQL statements. This is convenient for incomplete information. Many of them need to guess by themselves or use sqlserver's event tracker to track and see how sqlserver Manager works.

In. net. The dbconnection object has a getschema method, which is very powerful and can obtain a lot of database architecture information, which is generally enough for us. However, simply use it to return the table name, as shown below:

String [] restrictions = new string [4];
Restrictions [3] = "base table"
Datatable table = connection. getschema ("tables", restrictions );

As shown in the above Code, all the user table schema information in the database can be filled in the datatable.

The following information is returned for tables:

 

For other architecture information, see the description in msdn.

The most convenient way to obtain schema information for each table is to use dataadapter. fillschema. The example is as follows:

 

Sqlcommand cmd = connection. createcommand ();
Cmd. commandtext = "select * from" + tblsection. tablename + "where 0 = 1"
Sqldataadapter da = new sqldataadapter (CMD );
Datatable tbltable = new datatable ();
Da. fillschema (tbltable, schematype. source );

In this way, you can easily read the complete architecture information of the table from the tbltable.

Appendix: there are various methods to obtain the database architecture, and the research is dizzy. Under. net, this is the simplest method I have found.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.