本文介绍了如何使用脚本代码为我的数据库创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我在一个文件夹中有40个表的脚本.我想使用此脚本文件在我的数据库中创建表.请任何人帮助,如何一次使用此脚本创建表.
谢谢
Hai,
I have a Script for 40 tables which is in one folder. I want to create table to my database using this script file. Please anybody help, how to create tables using this script at a time.
Thank you
推荐答案
//create DB
string sqlString = string.Format("USE [master] CREATE DATABASE {0}", dbName);
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand(sqlString, conn);
bool err = false;
try
{
conn.Open();
int r = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
created = "\nCreate database failed: " + ex.Message;
err = true;
}
conn.Close();
if (err) return created;
参见codeproject链接:
使用Installer类轻松部署SQL Server数据库 [ ^ ]
链接摘录:
see codeproject link:
Deploy SQL Server databases easily with an Installer class[^]
excerpt from link:
//delete all GO cmds
sr = new StreamReader("CreateTables.sql");
readsql = sr.ReadToEnd();
Regex regex = new Regex("^GO", RegexOptions.IgnoreCase | RegexOptions.Multiline);
string[] SqlLine = regex.Split(readsql);
这篇关于如何使用脚本代码为我的数据库创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!