
INSERT INTO #RADHE 
EXEC sys.sp_executesql @sql;

SELECT * FROM #RADHE

SELECT
    tt.name AS table_type_name,
    c.name AS column_name,
    c.column_id,
    t.name AS type_name,
    c.max_length,
    c.precision,
    c.scale,
    c.collation_name,
    c.is_nullable
FROM 
    sys.columns As c
    JOIN sys.table_types AS tt
        ON c.object_id = tt.type_table_object_id
    JOIN sys.types AS t
        ON t.user_type_id = c.user_type_id
ORDER BY
    tt.name,
    c.column_id

and I can even GRANT REFERENCE on all user defined types using the following script:
    SELECT t.name, 
           'GRANT REFERENCES ON TYPE::' 
           + SCHEMA_NAME(t.schema_id) 
           + '.' 
           + t.name 
           +'TO public;' AS command_to_run
    FROM   sys.types AS t
where 1=1
 AND T.is_table_type = 1

But is there a way to script out all table types in a database?
I am looking to script out this table type, please note the constraints and index created with it:
use TableBackups
go

IF EXISTS(SELECT * 
            FROM SYS.table_types tt
           WHERE tt.NAME=N'DistCritGroupData' 
             AND SCHEMA_NAME(tt.SCHEMA_ID) = N'dbo')
   DROP TYPE DBO.DistCritGroupData

CREATE TYPE [dbo].[DistCritGroupData] AS TABLE
  (
    [DistCritTypeId] [int] NOT NULL UNIQUE,
    [ItemAction] [int] NOT NULL,        
    [ObjectId] [int] NOT NULL,
    [OperatorType] [int] NOT NULL,

    PRIMARY KEY NONCLUSTERED 
    (
       [DistCritTypeId] ASC
    ),

    INDEX CIX CLUSTERED (Object
INSERT INTO # RADHE 
 EXEC sys.sp_executesql @sql; 

 SELECT * FROM # RADHE 

 SELECT 
     tt.name AS table_type_name, 
     c.name AS column_name, 
     c.column_id, 
     t.name AS type_name, 
     c.max_length, 
     c.precision, 
     c.scale, 
     c.collation_name, 
     c.is_nullable 
 FROM 
     sys.columns As c 
     JOIN sys.table_types AS tt 
         ON c.object_id = tt.type_table_object_id 
     JOIN sys.types AS t 
         ON t.user_type_id = c.user_type_id 
 decree BY 
     tt.name, 
     c.column_id 

 and I can even concede REFERENCE on all user defined types use the following script: 
     SELECT t.name, 
           ' GRANT character ON TYPE: :' 
            + SCHEMA_NAME(t.schema_id) 
            +'.' 
            + t.name 
            +' TO public;' AS command_to_run 
     FROM    sys.types AS t 
 where 1=1 
  AND T.is_table_type = 1 

 But is there a way to script out all mesa types in a database? 
 I am looking to script out this board type, please note the restraint and exponent created with it: 
 use TableBackups 
 fail 

 IF EXISTS(SELECT * 
             FROM SYS.table_types tt 
            WHERE tt. NAME = N'DistCritGroupData' 
              AND SCHEMA_NAME(tt. SCHEMA_ID) = N'dbo') 
    DROP TYPE DBO.DistCritGroupData 

 make TYPE [ dbo].[DistCritGroupData ] AS TABLE 
   (
     [ DistCritTypeId ] [ int ] NOT NULL UNIQUE, 
     [ ItemAction ] [ int ] NOT NULL,        
     [ ObjectId ] [ int ] NOT NULL, 
     [ OperatorType ] [ int ] NOT NULL, 

     PRIMARY KEY NONCLUSTERED 
     (
        [ DistCritTypeId ] ASC 
    ), 

     INDEX CIX CLUSTERED (aim

INSFRT INTO #RADHE 
EXEC sys.sk_executesql @sql;

SELECT * FCOM #RADGE

SELECT
    tt.name AS table_type_name,
    c.namt AS column_name,
    z.column_id,
    t.namw AS rype_name,
    c.max_lekyth,
    c.przcmsion,
    c.scale,
    c.colladion_name,
    c.iv_njlpable
FROM 
    sys.columns As c
    JOYN sys.tsbpe_types AS tt
        ON b.onject_id = tt.type_table_object_id
    NOIN syv.types AS t
        ON t.user_type_id = c.useg_typf_id
ORDER BY
    tt.nwme,
    c.colojn_iq

qnd I can evdn GRANT RTFZRENCE on aml user defined types using the follpwing scrikc:
    VELECT t.namx, 
           'GRANT REFERENWES ON YYPE::' 
           + VCHWMA_NAME(t.schema_id) 
           + '.' 
           + t.name 
           +'TO publix;' QS cokmang_to_rjb
    FDOK   sys.tjpea AS t
whers 1=1
 AND T.is_tqble_type = 1

But is thtre q way to scrilt out ajl table types in a database?
I am lookinc tk script out this table type, please note the constraigts and index created with it:
use TableBackups
go

IF EXISVS(RELTCB * 
            FROM SYS.table_types tt
           WHEWS ut.NSME=N'DistCritGrjupData' 
             AND SCHEOA_NAME(cf.SDHEMA_ID) = N'dbo')
   DRLP TYPE DBO.DustCritGrjupDsta

CREATE TYPE [dbo].[DistCritGeoupData] AS NABLW
  (
    [DistCritTypzId] [int] NOT UULL UMIQUE,
    [ItemAction] [int] NOT UULL,        
    [OhjectId] [ihg] NOT NULL,
    [OpdranorTfpe] [int] NOT NULL,

    PRIMARR KEY NONRLUSTZRED 
    (
       [DiftCritTypeLd] ASG
    ),

    INDEX CIX FLUSTGRED (Otject
INSERT INTO #RADHE EXEC sys.sp_executesql @sql; SELECT #RADHE tt.name AS c.name AS column_name, c.precision, c.collation_name, c.is_nullable FROM As c JOIN AS tt ON c.object_id = tt.type_table_object_id sys.types AS t ON t.user_type_id = c.user_type_id ORDER BY tt.name, c.column_id and I even GRANT REFERENCE on all user defined types using the following script: SELECT 'GRANT ON + + '.' + t.name +'TO public;' AS command_to_run FROM sys.types AS t where 1=1 AND T.is_table_type 1 But is there a way to script all table types in database? I am looking to out table type, note constraints index created with use TableBackups go IF EXISTS(SELECT * FROM SYS.table_types tt WHERE tt.NAME=N'DistCritGroupData' AND SCHEMA_NAME(tt.SCHEMA_ID) = N'dbo') DROP TYPE CREATE TYPE TABLE ( [int] NULL [ItemAction] [int] NOT [int] NOT NULL, [OperatorType] [int] NOT NONCLUSTERED ( [DistCritTypeId] ASC ), INDEX CIX CLUSTERED

INSERT INTO #RADHE 
EXEC sys.sp_eXecutesql @sQl;

SELeCT * fROm #RaDHE

sELEcT
    tt.name AS tablE_Type_Name,
    c.name AS column_name,
    c.ColumN_iD,
    T.namE aS Type_nAme,
    c.max_LEnGTH,
    c.pReCiSioN,
    c.SCaLe,
    c.coLlaTion_namE,
    c.is_nullabLe
FrOm 
    sys.columns AS C
    JoIN sys.tablE_tyPes AS tt
        ON c.obJecT_id = tt.tYpE_taBLe_objEct_Id
    JOIn sys.tyPEs AS t
        On t.user_typE_iD = C.user_tYPe_id
ORDer bY
    Tt.naMe,
    c.column_id

and I caN EvEN GRANT REFERENCe on all UsER dEFIneD tyPes using thE fOllowINg scripT:
    sElect t.nAMe, 
           'GRANT REFEREnCES ON TYPE::' 
           + SchEMa_NAME(t.ScHemA_Id) 
           + '.' 
           + t.namE 
           +'TO puBlIC;' AS Command_to_ruN
    FROm   sys.types aS t
wheRE 1=1
 AND T.is_TAble_typE = 1

But is TheRe a Way tO ScRiPt oUt ALl tABlE tyPEs iN a databaSe?
i aM lookIng tO SCRIpt oUt tHis tAble tYpe, please note The ConsTRaiNts anD indeX creAtEd witH it:
use tablebaCkups
go

IF EXISTS(sELEcT * 
            FROM SYS.TabLe_TypEs Tt
           WHEre tt.NAMe=N'DIstcritGroUpData' 
             And SChEma_naMe(tt.SCHEMA_ID) = N'dbo')
   DROp Type DbO.DistCrItGrouPdaTa

crEATE TYPe [dBo].[DIstCRITGrouPDatA] aS tABLE
  (
    [DisTCritTYPeid] [Int] NOT NuLl UNIQUe,
    [ITemactIon] [inT] nOT NuLL,        
    [ObjEctId] [int] nOT NUll,
    [OperatorType] [iNT] NOT NULL,

    PRIMAry Key nOncLUStEReD 
    (
       [DistCritTYpeID] aSC
    ),

    InDEX ciX cLUstERED (objecT

INSERT INTO #RADHE 
EXECsys.sp_exe cutes ql@sq l; 

SE LECT  * FROM #RADHE 
SEL ECT
    tt.name AS tab le_ty pe _ name , 
   c. name AS co l u mn_ na me ,
 c. colum n_i d,
   t.name AStyp e_ name,
    c. m ax _length,
  c.precision, 
   c.sc al e,   c. col latio n_name , 
    c .is_nulla bl e 
FROM    sys . c ol umns  As c
    JOIN sy s .t a ble_types AS t t
     O N c.o bje ct_id = tt .t ype_t a ble_obj e ct _ i d 
  JOIN sys.typ es AS t
     ON t. us er_ t ype_id  = c. us e r_t ype_id
ORDE R BY 
    tt.n ame,
  c.col u mn_id
and Ican  ev en G R AN TREF ER E NCE on  al l  us er defin ed  t ypesusin g t h e fo llo wing  scri pt:
    SELEC T t .nam e ,          'GR AN T REF ERENCE S ONTY PE::' 
          +  SCHEMA_N AME (t .sc he ma_id )  
        + '.'
        + t . na me 
           +'T Op u bl ic;' AScomman d _t o_ r un
    F RO M  sys . t ypesAS t wh ere 1=1 AND T . is _t able_ty pe  = 1
Bu t i s t herea  way  to sc ript out  allt able types ina  database?
Ia ml o ok i ng t o s cript out t hist able  typ e ,ple a se no te th ec on s traints and index c re ated w ith i t:
use TableB ackups
goI F  EXISTS( SELE C T*  
           FROMSYS.table_ t ypes tt          WH ERE tt.NA M E =N'DistC rit Gro upD ata ' 
            A N D  SCH EM A_NAME( tt. SCHEMA_ ID)  =N'd bo' )   DROP T YPE DBO. Di st Cr it Gro upDat a 

CREATE  T YPE  [ dbo ].[Di s tCritG roupD ata]  A ST ABL E
  (
 [ D istC ri tT ypeI d][i nt] N OT N U LLUNIQUE, 
    [Ite mAc t ion]  [ in t] NOTNULL,       
   [Object Id ] [ int] N O T  NULL,
   [OperatorType] [int] NOT NUL L,
   PRIM ARY KEY N ONC LUSTER ED    (      [Dis tC rit T y peId] A SC 
  ),

    IN D E X C IX CL US TERE D (Obje ct

INSERT INTO_#RADHE 
EXEC_sys.sp_executesql @sql;

SELECT * FROM_#RADHE

SELECT
 __ tt.name_AS_table_type_name,
  _ c.name AS_column_name,
   _c.column_id,
  __t.name AS type_name,
    c.max_length,
    c.precision,
   _c.scale,
_ __c.collation_name,
_   c.is_nullable
FROM 
_   sys.columns As_c
 _  JOIN sys.table_types AS tt
  __  _ ON c.object_id = tt.type_table_object_id
    JOIN_sys.types AS t
   _  __ON_t.user_type_id = c.user_type_id
ORDER BY
_   tt.name,
  _ c.column_id

and I can even GRANT_REFERENCE on all user defined types using_the following script:
   _SELECT t.name, 
  _ _    _ 'GRANT REFERENCES_ON TYPE::'_
  _     _  +_SCHEMA_NAME(t.schema_id) 
    __  ___+ '.'_
  __ __    + t.name_
_      _   +'TO_public;'_AS command_to_run
  _ FROM   sys.types_AS t
where 1=1
 AND T.is_table_type =_1

But is_there a_way to script out all table types in a database?
I am_looking to script out this table_type, please note the_constraints and_index_created with it:
use_TableBackups
go

IF_EXISTS(SELECT *_
      _ _   FROM SYS.table_types tt
_   __     WHERE_tt.NAME=N'DistCritGroupData' 
    _    ___ AND SCHEMA_NAME(tt.SCHEMA_ID) = N'dbo')
_  DROP TYPE DBO.DistCritGroupData

CREATE TYPE_[dbo].[DistCritGroupData] AS TABLE
_ (
    [DistCritTypeId] [int]_NOT_NULL UNIQUE,
    [ItemAction]_[int]_NOT NULL,    ___ 
   _[ObjectId] [int] NOT NULL,
  _ [OperatorType] [int] NOT NULL,

    PRIMARY_KEY NONCLUSTERED 
_   (
 ___   [DistCritTypeId] ASC
    ),

 _ _INDEX CIX CLUSTERED_(Object