Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Altering a table, re-aliasing related views.

Author  Topic 

TheCurved
Starting Member

3 Posts

Posted - 2011-08-24 : 00:43:10
Hello forum people, I hope someone out there can help me out with an issue I'm having. I've tried googling the problem but no luck.

I am adding a new column to a table using the alter table syntax. This is updating all of the views that reference that table.

The problem I am having is related to the views that use both the updated table and is joined to another table and has all of the updated tables columns referenced.

What happens is that all of the columns that is listed in the view after the newly add column has an alias added but the alias references the previous column!

So in .NET, using the example in the image I've attached, the code errors because returning the column "store" would actually give me the newly added column "accountemailaddress".

The reason this is such an issue is because I have to update all the views (annoying) and there are hundreds of them. This is a major pain.

Any help would be wonderful.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-24 : 00:49:28
It sounds like you are using * in your code. Don't use * and you'll avoid this problem. Let me know if I'm not understanding your problem.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

TheCurved
Starting Member

3 Posts

Posted - 2011-08-24 : 00:55:25
Thanks for replying, the * is used in the views to return all of the columns. I am not the original coder so I do not know why the views are coded this way.

Do you know of a way I can alter the table and not add the new column to theses views?

There are far too many views to have to change each and everyone to not select *.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-24 : 01:06:00
To fix this problem, you will need to modify every one of these views and remove *, and the explicitly write out your columns. There is no other way.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

TheCurved
Starting Member

3 Posts

Posted - 2011-08-24 : 01:08:43
Again, thanks. So then, is there a way to stop having an alias assigned to the columns?
Go to Top of Page
   

- Advertisement -