Reputation: 21
I have a strange problem here; as I searched through the internet, including StackOverflow, the best, simpliest and fastest way to create data base only when such does not exists is using the following SQL query:
CREATE DATABASE IF NOT EXISTS DataBase1
However, when I parse this statement in my C# code I get this error:
Incorrect syntax near the keyword 'IF'. Incorrect syntax near 'DataBase1'.
The same happens when I try to execute the query in SSMS; I get:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'IF'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'DataBase1'.
Can you tell me what am I doing wrong?
Upvotes: 0
Views: 5947
Reputation: 77876
You haven't posted your code but your sql statement should looks like
string sql = "CREATE DATABASE IF NOT EXISTS `DataBase1`;";
Upvotes: 0