This is a kind of hack, but it seems to work. Below are the steps and an example of changing the type of a table. One note: sp_refreshsqlmodule will fail if the change you make to the table type is a violation of this object, usually a procedure.
- Use
sp_rename to rename the table type, I usually just add z to the beginning of the name. - Create a new table type with the original name and any changes you need to make a table type.
- Go through each dependency and run
sp_refreshsqlmodule on it. - Drop the renamed table type.
EXEC sys.sp_rename 'dbo.MyTableType', 'zMyTableType'; GO CREATE TYPE dbo.MyTableType AS TABLE( Id INT NOT NULL, Name VARCHAR(255) NOT NULL ); GO DECLARE @Name NVARCHAR(776); DECLARE REF_CURSOR CURSOR FOR SELECT referencing_schema_name + '.' + referencing_entity_name FROM sys.dm_sql_referencing_entities('dbo.MyTableType', 'TYPE'); OPEN REF_CURSOR; FETCH NEXT FROM REF_CURSOR INTO @Name; WHILE (@@FETCH_STATUS = 0) BEGIN EXEC sys.sp_refreshsqlmodule @name = @Name; FETCH NEXT FROM REF_CURSOR INTO @Name; END; CLOSE REF_CURSOR; DEALLOCATE REF_CURSOR; GO DROP TYPE dbo.zMyTableType; GO
Attention:
This can be damaging to your database, so you should check this out in the development environment first.
norlando May 22 '15 at 18:04 2015-05-22 18:04
source share