C# sql 서버 데이터베이스 만들기

1399 단어
       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);
       }

좋은 웹페이지 즐겨찾기