Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify hardcoded database name - SQL Server 2008 r2

Tags:

sql

sql-server

I need to find a way to determine what object in a database has the original database name hardcoded into it. I've restored a copy of a database under a different name and run homegrown scripts to make all the naming adjustments. Let's say the original DB was named ABC_Db and the restored copy has been renamed to XYZ_Db. When I attempt to perform an UPDATE on CoreTable, I get

Invalid object name 'ABC_Db.dbo.CoreTable'

I've queried against the syscomments and done various manual checks against relations and indexes, etc. with no luck. What's next?

Thanks,

John

like image 223
John Spiegel Avatar asked Sep 11 '26 23:09

John Spiegel


1 Answers

To find it

SELECT
   OBJECT_NAME(object_id)
FROM
   sys.sql_modules
WHERE
   definition LIKE '%ABC_Db%'

syscomments is unreliable for long code.

sys.sql_modules covers all code and is safe for all objects

like image 70
gbn Avatar answered Sep 14 '26 16:09

gbn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!