I am not getting option like 'ALTER TO' when am right clicking on TVP
To modify the data that is passed to a stored procedure or parameterized statement in table-valued parameter, you must insert the data into a temporary table or into a table variable. You cannot use ALTER TABLE statements to modify the design of table-valued parameters.
Table-valued parameters are declared by using user-defined table types. You can use table-valued parameters to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters.
Can't do it. You must drop/recreate. If you have dependencies on the TVP, you must:
I've found a blog post on sqltreeo.com which has a way to automate the process by temporary dropping the dependencies and then re-creating them.
I just modified it a bit.
1.You should create the following procedure:
-- Find all referencing objects to user-defined table type in @fullObjectName parameter -- and generate DROP scripts and CREATE scripts for them CREATE PROC [dbo].[alterTableType] (@fullObjectName VARCHAR(200)) AS BEGIN SET NOCOUNT ON IF (TYPE_ID (@fullObjectName) IS NULL) BEGIN RAISERROR ('User-defined table type ''%s'' does not exists. Include full object name with schema.', 16,1, @fullObjectName) RETURN END; WITH sources AS ( SELECT ROW_NUMBER() OVER (ORDER BY OBJECT_NAME(m.object_id)) RowId, definition FROM sys.sql_expression_dependencies d JOIN sys.sql_modules m ON m.object_id = d.referencing_id JOIN sys.objects o ON o.object_id = m.object_id WHERE referenced_id = TYPE_ID(@fullObjectName) ) SELECT 'BEGIN TRANSACTION' UNION ALL SELECT 'DROP ' + CASE OBJECTPROPERTY(referencing_id, 'IsProcedure') WHEN 1 THEN 'PROC ' ELSE CASE WHEN OBJECTPROPERTY(referencing_id, 'IsScalarFunction') = 1 OR OBJECTPROPERTY(referencing_id, 'IsTableFunction') = 1 OR OBJECTPROPERTY(referencing_id, 'IsInlineFunction') = 1 THEN 'FUNCTION ' ELSE '' END END + SCHEMA_NAME(o.schema_id) + '.' + + OBJECT_NAME(m.object_id) FROM sys.sql_expression_dependencies d JOIN sys.sql_modules m ON m.object_id = d.referencing_id JOIN sys.objects o ON o.object_id = m.object_id WHERE referenced_id = TYPE_ID(@fullObjectName) UNION ALL SELECT 'GO' UNION ALL SELECT CHAR(13) + CHAR(10) + '---- WRITE HERE SCRIPT TO DROP OLD USER DEFINED TABLE TYPE AND CREATE A NEW ONE ----' + CHAR(13) + CHAR(10) UNION ALL SELECT CASE WHEN number = RowId THEN DEFINITION ELSE 'GO' END FROM sources s JOIN (SELECT DISTINCT number FROM master.dbo.spt_values) n ON n.number BETWEEN RowId AND RowId+1 UNION ALL SELECT 'COMMIT' END
2.Then you should run it with your table type name as a input parameter. Show the results on grid format (because text format might truncate long texts), select entire result table and copy it to a new query window.
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