If call CREATE DATABASE foo twice I get the error message:
Msg 1801, Level 16, State 3, Line 1
Database 'dropme' already exists. Choose a different database name.
The error message is listed in sys.messages:
SELECT * FROM sys.messages WHERE message_id = 1801 AND language_id = 1033
I have a SQLCLR procedure that basically does a CREATE DATABASE FOR ATTACH. It knows the name of the created database at the beginning, but does a lot of work before attaching it. Therefore, I'd like to make sure the database doesn't exist before proceeding and give that error if it does.
If I try to use RAISERROR(1801, 16, 1) on that message it will not let me:
Msg 2732, Level 16, State 1, Line 1
Error number 1801 is invalid. The number must be from 13000 through 2147483647 and it cannot be 50000.
Do I have any option other than raising the error and having the msg_id being 50000?