【发布时间】: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