SQL Server - Return SCHEMA for sysobjects

后端 未结 8 1473
旧巷少年郎
旧巷少年郎 2020-12-29 21:30

How to I get the SCHEMA when doing a select on sysobjects?

I am modifing a stored procedure called SearchObjectsForText which returns only the Name

8条回答
  •  忘掉有多难
    2020-12-29 22:18

    Instead of a view, why not use this to populate a temporary table you can use?

    This is the solution I use in stored procedures

    This is the best way to get a schema dynamically and add it to the different tables within a database in order to get other information dynamically

    select @sql = 'insert #tables SELECT ''[''+SCHEMA_NAME(schema_id)+''.''+name+'']'' AS SchemaTable FROM sys.tables'

    exec (@sql)
    

    of course #tables is a dynamic table in the stored procedure

提交回复
热议问题