r/SQLServer • u/zeocrash • Oct 01 '25
Question Wrapping table functions in views
I've inherited a project.
When the original developer created a table valued function often he would wrap the function call in a view
E.g
SELECT *
FROM SomeFunction()
In most of these cases, there's no where clause or parameter passed to the function.
Is there any good reason to structure code like this?
I can't think of any good reasons, buti just wanted to check I wasn't missing something.
2
Upvotes
3
u/Disastrous_Fill_5566 Oct 01 '25
Might to be make it easier for them to integrate with an ORM or some other generated SQL in an application.
2
u/Malfuncti0n Oct 01 '25
Let's say the view is used in 5 spots, reports, STPs or whatever.
If you change the function (eg, passing of parameters) you'd have to change it in 5 spots if it wasn't wrapped in a view. Now only 1.
1
u/SirGreybush 1 Oct 01 '25
Probably just for testing, or unit testing, to check that it works, by doing select * from view_name, or select count(*) from view_name
2
u/xxxxxxxxxxxxxxxxx99 Oct 01 '25
Some reporting tools (possibly PowerBI) don't know how to get data from functions, and only make tables and views available for querying.
1
u/TOPHATANT123 Oct 07 '25
It could be to make it easier to swap out the TVF in the future for a different one, but then again you could just change the existing TVF.