I have a table-valued function (TVF) in SQL Server that looks like this:
CREATE FUNCTION TVF_xyz(@AuditKey INT)
RETURNS TABLE
AS
RETURN
SELECT *
FROM xyz
WHERE AUDIT_KEY = @AuditKey
GO
Now, I added a new column to the xyz
table.
When I query using TVF_xyz
, it doesn't show me the new column (shows all other columns except newly added).
Query:
SELECT TOP 10 *
FROM TVF_xyz (1543)
I would like to know, how to refresh TVF to show new column.
PS: Select *
used in TVF to fetch all columns.
You cannot update a table-valued function.
An UPDATE statement is used to update the quantity of the item specified by itemNo in table Inventory , by the amount specified by amount . A result set containing the product name and the new quantity of the item is returned. Note that the MODIFIES SQL DATA clause is used because function updates table data.
A table function, also called a table-valued function (TVF), is a user-defined function that returns a table. You can use a table function anywhere that you can use a table. Table functions behave similarly to views, but a table function can take parameters.
After bit of searching, I found sp_refreshsqlmodule (Transact-SQL), its common behavior of TVF.
In order to refresh TVF, following SP needs to be executed:
EXEC sys.sp_refreshsqlmodule 'TVF_xyz'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With