You can use a number for a table name (or database name, or schema name - see my comment), however, you will need to escape it with []
:
select *
into [123].[456].[789]
from OtherTable;
Where [123]
represents database, [456]
represents schema and [789]
represents a table.
Edit
In the interests of standardisation, e.g. if there is a chance of future portability between RDBMS, note that preference should be given to use double quotes "
instead of []
for escaping, e.g.
SELECT * from "123"."456"."789";
You will however need to ensure that set QUOTED_IDENTIFIER ON
is set on the connection.
If the names of objects are being constructed dynamically, note that it is also possible to override the default escaping of the QUOTENAME
function by providing a character delimiter as the second parameter, e.g.:
select QUOTENAME('123', '"');