SQL Server Database Name Reference -
hello sql server experts,
i have unusual issue i'm hoping feedback on potential solutions for: working application requires odbc connection existing sql database. however, database contains dash ("-") in name, causes syntax error in application (obviously not outstanding development effort, there nil can this).
as temporary solution problem, created re-create of database , renamed without dash. target database used specific tasks , not updated often, update every few months, means periodically have go in , refresh it. expecting have solution developer now, not cooperating.
my question is: there solution issue wouldn't involve me having refresh re-create of database? should mention renaming original database not option. should setup sql job periodic restore of target database copy?
is synonym possible solution?
thanks!
edit: couple of people have pointed out utilize of square brackets -- not option. application gui gives me error when seek utilize brackets in db name field.
major hack alert - create synonyms not database, in it!
if app needs access objects supported synonyms, potentially create db improve name , fill synonyms of original db's objects:
create database mydatabase; go utilize mydatabase; go create synonym [dbo].[mytable1] [my-database].[dbo].[mytable1]; create synonym [dbo].[myview2] [my-database].[dbo].[myview2]; create synonym [dbo].[myproc3] [my-database].[dbo].[myproc3]; ...
here bit of generation script help this:
declare @olddbname sysname = 'my-database' select 'create synonym ' + quotename(schema_name(schema_id)) + '.' + quotename(name) + ' ' + quotename(@olddbname) + '.' + quotename(schema_name(schema_id)) + '.' + quotename(name) + ';' sys.objects schema_name(schema_id) not in ('sys') , type in ('af', 'fn', 'fs', 'ft', 'if', 'p', 'pc', 'rf', 'tf', 'u', 'v', 'x')
sql database sql-server-2008 tsql synonym
No comments:
Post a Comment