The syntax for this is explained here:
However, my code is implemented like this:
public static bool CreateDatabaseIfNotExists(string connectionString, string databaseName)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand(
string.Format("SELECT * FROM sys.databases WHERE [name]=\'{0:S}\'", databaseName),
conn);
cmd.CommandTimeout = int.MaxValue;
if (cmd.ExecuteScalar() == null)
{
SqlCommand cmd2 = new SqlCommand(
string.Format("CREATE DATABASE [{0:S}];", databaseName),
conn);
cmd2.CommandTimeout = int.MaxValue;
cmd2.ExecuteNonQuery();
return true;
}
else
return false;
}
}
Where exactly should I put the basic string, as I am not sure where to place it.
You specify the edition after the name of the DB:
SqlCommand cmd2 = new SqlCommand(string.Format("CREATE DATABASE [{0:S}] (SERVICE_OBJECTIVE = 'basic');", databaseName), conn);
The documentation for the syntax can be found here