Search code examples
sqlsap-aseuser-defined-types

How to get a list of user defined data types on Sybase ASE?


I use the following query to get the list of user defined data types (UDDTs):

SELECT USER_NAME(S.uid) as owner, S.name as Name, T.name as datatypename, 
         OBJECT_NAME(S.domain), OBJECT_NAME(S.tdefault) 
FROM systypes S,systypes T 
WHERE S.type=T.type AND T.usertype<100 AND T.usertype NOT IN(18,24,25,80) AND S.usertype>100  
ORDER BY 1, 2

On Sybase 12.5, it used to return to return a single row per UDDT. Now with Sybase 15.x, it returns 2 rows:

owner   Name    datatypename 
'dbo'  'auid'  'varchar'
'dbo'  'auid'  'longsysname'

The datatype of the UDDT is actually varchar. I am not sure where the longsysname is coming from. What is the correct way to return the list of UDDTs that works in both 12.5.x and 15.x ASE databases?


Solution

  • Try this code:

    select s1.name, 
            (select name 
             from systypes s2 
             where s2.usertype=(
                                select min( s3.usertype) 
                                from systypes s3 
                                where  s3.hierarchy=s1.hierarchy)
            ) base_type,  USER_NAME(s1.uid) as owner
        from systypes s1
        WHERE s1.usertype>100