【问题标题】:List all procedures that would pertain to ambiguous column error in SqlServer列出与 Sql Server 中的歧义列错误有关的所有过程
【发布时间】:2014-01-07 20:05:45
【问题描述】:

请在下面找到问题的场景和描述。

场景

--Step 1 creating tables 

create table table_A (id int not null,category varchar(20))  
create table table_B (id int not null)  
GO

/*step 2 creating procedure and joining those tables.  
 Here you can see there is no alias name specified in select list   
 as there is only one column as "category"   
*/  
create proc dbo.proc_ambiguous_columns  
as  
begin   

    select a.id,b.id,category  
    from table_A a  
    join table_B b  
    on a.id = b.id 

end  
Go  

--step 3 Executing the proc will not result in an error  

exec proc_ambiguous_columns   
GO  

--Step 4 creating a new column with same name in table_B  

alter table table_B add category varchar(20)  
Go  

/*step 5 Now execute the proc which will result in an error message as  
"Msg 209, Level 16, State 1, Procedure proc_ambiguous_columns, Line 5  
Ambiguous column name 'name'"*/  

exec proc_ambiguous_columns  
GO  

要求:

我能否在最终选择列表中获取所有正在引用/选择的列名“类别”的程序列表,以便我可以将别名放在所有程序中新添加的列中。

【问题讨论】:

    标签: sql-server


    【解决方案1】:
    SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES 
    WHERE ROUTINE_DEFINITION LIKE '%category%' 
    AND ROUTINE_TYPE='PROCEDURE'
    

    另外,请在此处查看答案:How do I find a stored procedure containing <text>?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多