C#创建sqlserver数据库

       public void CreateDatabase(string lx,string yf) {
           string sqlPart = @"
if not exists(select * from master.sys.databases t where t.name='{0}')
begin
	create database hc on primary (name = N'{0}',filename=N'D:\data\{0}.mdf',size = 3072KB, filegrowth = 1024Kb)
		log on (name = N'{0}_log',filename = N'd:\data\{0}_log.ldf',size = 1024KB,filegrowth = 10%)
end


if not exists(select * from master.sys.databases t where t.name='{0}{1}')
begin
	create database {0}{1} on primary (name = N'{0}{1}',filename=N'D:\data\{0}{1}.mdf',size = 3072KB, filegrowth = 1024Kb)
		log on (name = N'{0}{1}_log',filename = N'd:\data\{0}{1}_log.ldf',size = 1024KB,filegrowth = 10%)
end


if not exists(select * from master.sys.databases t where t.name='{0}fx{1}')
begin
	create database {0}fx{1} on primary (name = N'{0}fx{1}',filename=N'D:\data\{0}fx{1}.mdf',size = 3072KB, filegrowth = 1024Kb)
		log on (name = N'{0}fx{1}_log',filename = N'd:\data\{0}fx{1}_log.ldf',size = 1024KB,filegrowth = 10%)
end

";

           string sql = string.Format(sqlPart,lx,yf);
           MyCommon.WriteLog(sql);
           MyCommon.ExecuteSql(sql, new SqlConnectConfig(".\\sqlexpress","master","xx","xx").ConnectString);
       }

 

你可能感兴趣的:(C#创建sqlserver数据库)