Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to Script All Data Types?

Author  Topic 

jbates99
Constraint Violating Yak Guru

396 Posts

Posted - 2011-02-10 : 18:16:52
Hi experts,

Well, the Subject line says it all.

I'm trying to find a way to script ALL user data types in a 2005 database. Seems that you can't do it using Management Studio but maybe someone has a script. There are hundreds of user data types and it will be very painful to create them manually.

Thanks, John

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-10 : 19:25:14
Do you mean user defined datatypes?

You can get the datatypes of all existing table columns using

SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.Columns
GROUP BY DATA_TYPE



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2011-02-10 : 23:32:15
scriptdb will do this for you, using SMO: http://scriptdb.codeplex.com



elsasoft.org
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-02-11 : 05:03:41
Hundreds of user data types? I though user data types were used to standardize on a few only...

- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-11 : 05:08:05
there are probably hundreds of user and each create their own data type ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-02-11 : 06:31:23
Just don't know what is this fantasy with user defined data types.Till now I have created not more than 2 or 3 user defined data types in my whole career.

PBUH

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-02-11 : 06:34:02
I mainly use them for describing table variables that I want to be able to pass into stored procs.

And yeah -- hundreds of different user data types????????

whoa.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

jbates99
Constraint Violating Yak Guru

396 Posts

Posted - 2011-02-11 : 14:15:37
Sachin - Oh I agree! I almost never create a user defined data type. But this is software that we (unfortunately) purchased.

Jezemine - Thanks for the script, i will try it.

yes these are USER data types.

Thanks to all of you.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-11 : 14:25:38
I love user-defined data type. So there!

Haven't used hundreds of them in a database though, maybe 20 at most.

You can also script out all user-defined type definitions using the Generate Scripts feature in Management Studio.
Go to Top of Page

jbates99
Constraint Violating Yak Guru

396 Posts

Posted - 2011-02-11 : 17:07:03
Yes robvolk I had found it by stumbling around. Right-click database name --> Tasks leads you to the form where you can select specific object types.

It is still running - I'm letting the script generate a .sql file.

Nice feature. Maybe in SQL Server xxxx they will do away with user data types. Nah.

John
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-11 : 17:20:40
quote:
Maybe in SQL Server xxxx they will do away with user data types
Only if they replace them with proper domains.

BTW, they added CLR data types and use them to implement of number of new data types in SQL 2008. Kinda pointless to add such a feature and then drop it 2 versions later (although they've done that a few times before)
Go to Top of Page
   

- Advertisement -