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
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
sys.syscomments
text is nvarchar(4000) so you can have issues with truncation when a definition splits across multiple rows. Try this instead.
select quotename(s.name)+'.'+quotename(o.name) as object_name, o.type_desc
from sys.sql_modules m
inner join sys.objects o
on m.object_id = o.object_id
inner join sys.schemas s
on o.schema_id = s.schema_id
where m.definition like '%ABC_Db%'
If you want to search through a Microsoft SQL Server database schema, the best tool is RedGate's SQL Search - and it's free. It's awesome.
http://www.red-gate.com/products/sql-development/sql-search/
最好的方法是生成数据库脚本并使用文本编辑器搜索文件工具来查找是否存在任何存储过程或其他代码中的内容。
是否有一个具有硬编码的完整对象名称的触发器?
SQL Prompt 5 has a feature called "Find Invalid Objects", which will identify stored procedures that reference objects that don't exist. It could be worth a try.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.