Error creating database name using full number in SQL Server 2008 R2

Create a database name using the string, the database will be created successfully.

Example:

if db_id('Database1') is null create database Database1 

The command completed successfully.

But create the database name using the full number, it has a problem

Example:

 if db_id('1234567890') is null create database 1234567890 

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '1234567890'.

Is there something wrong with my request?

+4
source share
2 answers

Try this option -

 IF DB_ID('1234567890') IS NULL CREATE DATABASE [1234567890] 
+5
source

You can also use double quote

 IF DB_ID('1234567890') IS NULL CREATE DATABASE "1234567890" 
+4
source

Source: https://habr.com/ru/post/1481895/


All Articles