Foreign key table primary key table

Source: Internet
Author: User

/// <Summary>
/// Query Method
/// </Summary>
/// <Param name = "tabnames"> tablename </param>
/// <Returns> dataset </returns>
Public dataset query (string tabnames, string columnname)
{
Using (oraclehelper orahp = new oraclehelper ())
{
String [] tabs = tabnames. Split (',');
Dataset DATA = new dataset ();
Orahp. open ();
For (INT I = 0; I <tabs. length; I ++)
{
String tabtemp = tabs [I];
String SQL = "select nvl (v. foreign key table, '"+ tabtemp +"') as foreign key table, AC. column_name column name, AC. data_type, AC. data_length, V. primary Key table, V. primary Key column, P. primary Key column PK, V. multiple options: AC. nullable from ";
SQL + = "(select S. table_name, S. column_name, S. data_type, S. data_length, S. nullable from all_tab_columns s where ";
If (columnname. length> 0)
SQL + = "S. column_name = '" + columnname + "'";
Else
SQL + = "S. column_name <> 'objectid '";
SQL + = "and S. Owner = '" + dbowner + "' and S. table_name = '" + tabtemp + "') ac ";
SQL + = "left Outer Join (select * From view_fk where foreign key table = '" + tabtemp + "') V on V. Foreign key column = ac. column_name ";
SQL + = "left Outer Join (select * From view_pk where table name = '" + tabtemp + "') P on AC. column_name = P. Primary Key column ";
If (columnname. Length <1)
SQL + = "Union select v. foreign key table, V. as column name of the foreign key column, 'varchar2' as type, 100 as length, V. primary Key table, V. primary Key column, null as PK, V. multiple options: 'n' as nullable from (select * From view_fk where primary key table = '"+ tabtemp +"') V ";

Oraclecommand comd = new oraclecommand (SQL );
Datatable datatab = new datatable ();
Datatab. tablename = tabtemp;
If (data. Tables. Contains (tabtemp ))
Continue;
Orahp. Execute (comd, datatab );
// Data. Tables. Add (datatab );
Data = changedt (datatab );
}
Orahp. Close ();

Return data;
}
}

Related Article

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.