我想使用c#
从其他数据库架构信息生成新的sql数据库以下代码显示了从数据库中检索信息
string connetionString = null;
SqlConnection connection;
SqlCommand command;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
string sql = null;
connetionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
sql = "Select DISTINCT(name) FROM sys.Tables";
connection = new SqlConnection(connetionString);
try
{
connection.Open();
command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
connection.Close();
DataSet dset = new DataSet();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
listBox1.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM "+ds.Tables[0].Rows[i].ItemArray[0].ToString()+"",connection);
ad.Fill(dset);
}
dset.Tables[0].WriteXml(@"E:\WindowsFormsApplication2\WindowsFormsApplication2\ds.xml");
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
同样明智的是,我必须从数据库中获取信息,并且必须使用此架构信息生成新的数据库。
答案 0 :(得分:0)
将架构从一个数据库复制到另一个数据库:
sp_help
存储过程)上调用sp_helptext
存储过程。对于MySQL,请使用SHOW CREATE TABLE
,SHOW CREATE PROCEDURE
和类似命令。这些返回用于创建对象的SQL。 请注意,您可以通过SQL Server Management Studio生成用于创建SQL Server数据库的SQL脚本。