Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to edit User Defined Type's column datatype


How to edit User Defined Type's column datatype

Author
Message
purushottam2
purushottam2
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 101
HI,

I need to changes User Defined Type's column datatype, and this UDT is using many stored procedure and user defined functions. And my application is live on production.

Is any way to edit UDT?
MVDBA
MVDBA
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2421 Visits: 860
And my application is live on production.Is any way to edit UDT?


you should really do this on a dev server and send it for test before you even think about live servers... i assume you have developer or express installed on your own desktop/laptop... why not do it on there first and at least you can unit test it before you think about going any further

HOWEVER you should be able to DROP and CREATE

see the example below which changes the UDT from bigint to int


create proc test as
declare @m dbo.test
set @m=1

GO
/****** Object: UserDefinedDataType [dbo].[test] Script Date: 08/29/2012 09:59:06 ******/
IF EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'test' AND ss.name = N'dbo')
DROP TYPE [dbo].[test]
GO


/****** Object: UserDefinedDataType [dbo].[test] Script Date: 08/29/2012 09:59:06 ******/
CREATE TYPE [dbo].[test] FROM INT NOT NULL
GO




MVDBA
purushottam2
purushottam2
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 101
Hi Mike,

Sure first i will do on local development environment.

Type is being use by many procedure and i dont want to touch those objects.
MVDBA
MVDBA
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2421 Visits: 860
as you can see from my example - i didn't touch the proc - just the UDT

MVDBA
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14971 Visits: 38989
I just tested this: you must drop all the objects that use the type, drop and recreate teh type, and then create all the objects that used to use it all over again.
otherwise you get an error referencing the first dependancy that SQL finds:

Msg 3732, Level 16, State 1, Line 1
Cannot drop type 'intVarcharForConCat' because it is being referenced by object 'ConcatStuff'. There may be other objects that reference this type.


here's a very simple example:

/* Create a user-defined table type */

CREATE TYPE intVarcharForConCat AS TABLE
(
ID int,
Descriptor VARCHAR(50)
);
--now a function that would do the FOR XML for concatenation.
GO
CREATE FUNCTION ConcatStuff(@MyTable dbo.intVarcharForConCat READONLY)
RETURNS TABLE WITH SCHEMABINDING
AS
RETURN(
SELECT DISTINCT
t.ID,
sq.Columns As Descriptors
FROM @MyTable t
INNER HASH JOIN (SELECT
ID,
Columns = STUFF(
(SELECT
',' + Descriptor
FROM @MyTable sc
WHERE sc.ID = s.ID
FOR XML PATH('')
)
,1,1,'')
FROM @MyTable s
) sq ON t.ID = sq.ID
)


GO

--test just the table type:
Declare @MyTable dbo.intVarcharForConCat

INSERT INTO @MyTable
SELECT OBJECT_ID,name from sys.columns

SELECT * FROM @MyTable
--test the concat function

SELECT * FROM dbo.ConcatStuff(@MyTable)


--try to drop and recreate just the type:
DROP TYPE intVarcharForConCat AS TABLE

CREATE TYPE intVarcharForConCat AS TABLE
(
ID int,
Descriptor VARCHAR(60)--creasing the size, for example
);
--now cleanup
DROP FUNCTION ConcatStuff
DROP TYPE intVarcharForConCat;



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

MVDBA
MVDBA
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2421 Visits: 860
i just did the same thing for a UDT (as per the original post) rather than a table type and you seem to be able to do it.... possibly because UDT originate from old school SQL

MVDBA
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search