Reputation: 167
I am using the following to create a database:
use master
IF DB_ID(N'delete') IS NULL
CREATE DATABASE delete
but get an error
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'delete'
because delete
is a reserved word. But is there no way of creating a database named "delete"?
Upvotes: 1
Views: 122
Reputation: 66
Delete is a reserved word, try [delete]
instead of delete
or choose a better database name e.g. itemstodelete
?
Upvotes: 0
Reputation: 222572
As you are seeing, delete
is a reserved word in most SQL databases.
You could quote the identifier. In T-SQL, which you seem to be using, you would do this with square brackets:
CREATE DATABASE [delete];
But I would not recommend that. From thereon, you will need to quote the database name each and every time you use it - if you fail to do that, you might encounter non-intuitive error messages. As I see it, there are enough words in the English language that we can avoid the very small subset of SQL reserved words (I would extend that to keywords too).
How about this, for example:
CREATE DATABASE db_delete;
Upvotes: 2