源程序如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DB;
namespace Ora2SQL
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox OraConn;
private System.Windows.Forms.TextBox SQLConn;
private System.Windows.Forms.DataGrid Grid;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.RichTextBox SQLText;
private System.Windows.Forms.ComboBox DBType;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Database db = new Database();
db.IsSqlDataBase = false;
db.IsSql = true;
db.ConnectionString = OraConn.Text;
DataSet ds;
string SQL = "SELECT a.table_name,a.column_name FROM all_cons_columns a, all_constraints b WHERE a.owner = b.owner AND a.constraint_name = b.constraint_name AND a.table_name = b.table_name AND b.constraint_type = 'P' and a.owner = 'DICTDB'";
db.RunProc(SQL,out ds);
Grid.DataSource = ds.Tables[0];
}
private void button2_Click(object sender, System.EventArgs e)
{
Database db = new Database();
db.IsSqlDataBase = false;
db.IsSql = true;
db.ConnectionString = OraConn.Text;
DataSet oratableds;
DataSet orads;
string SQL = "SELECT distinct(a.table_name) as table_name FROM all_cons_columns a, all_constraints b WHERE a.owner = b.owner AND a.constraint_name = b.constraint_name AND a.table_name = b.table_name AND b.constraint_type = 'P' and a.owner = '"+DBType.Text+"' ";
string ResultSQL = "";
bool flag;
db.RunProc(SQL,out oratableds);
string tablename="";
foreach(DataRow dr in oratableds.Tables[0].Rows){
tablename=Convert.ToString(dr["table_name"]);
SQL= "SELECT a.table_name,a.column_name FROM all_cons_columns a, all_constraints b WHERE a.owner = b.owner AND a.constraint_name = b.constraint_name AND a.table_name = b.table_name AND b.constraint_type = 'P' and a.owner = '"+DBType.Text+"' and a.table_name='"+tablename+"'";
db.RunProc(SQL,out orads);
ResultSQL += "ALTER TABLE "+tablename+" WITH NOCHECK ADD ";
ResultSQL += " CONSTRAINT PK_"+tablename+" PRIMARY KEY CLUSTERED ";
ResultSQL += "(";
flag = false;
foreach(DataRow sdr in orads.Tables[0].Rows){
if (flag)
ResultSQL += ","+Convert.ToString(sdr["column_name"]);
else
ResultSQL += Convert.ToString(sdr["column_name"]);
flag= true;
}
ResultSQL += ") go ";
}
SQLText.Text = ResultSQL;
}
private void Form1_Load(object sender, System.EventArgs e)
{
DBType.Items.Add("DICTDB");
DBType.Items.Add("USERDB");
}
}
}
目前的功能很简单,回头可以在改进改进。做成一个导入导出的小工具出来。


浙公网安备 33010602011771号