开发者

How to get all user defined datatypes in Sybase?

开发者 https://www.devze.com 2023-03-14 08:54 出处:网络
Could you 开发者_如何转开发please help me in finding all user defined datatypes in a sybase database.

Could you 开发者_如何转开发please help me in finding all user defined datatypes in a sybase database.

Thanks!


Note: I realise this was asked a while ago, but I came across it looking for the answer, so thought I'd put it here.

The types are all in systypes, however they are not clearly delineated into user and system types. It seems that all the system types have accessrule set to NULL, and all my user types have this set to 0, so I've used the following:

SELECT * FROM systypes WHERE accessrule != NULL

This is good enough for what I'm doing.

You can see more about the systypes table (and other related tables) at: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.tables/html/tables/tables69.htm


Since sybase is like SQL server using the profiler i got this query. If it does not work, use a profiler like tool for sybase, create a user defined type, and check the system tables it updates.

SELECT
'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Database[@Name=' + quotename(db_name(),'''') + ']' + '/UserDefinedDataType[@Name=' + quotename(st.name,'''') + ' and @Schema=' + quotename(sst.name,'''') + ']' AS [Urn],
st.name AS [Name],
sst.name AS [Schema],
baset.name AS [SystemType],
CAST(CASE WHEN baset.name IN (N'nchar', N'nvarchar') AND st.max_length <> -1 THEN st.max_length/2 ELSE st.max_length END AS int) AS [Length],
CAST(st.precision AS int) AS [NumericPrecision],
CAST(st.scale AS int) AS [NumericScale],
st.is_nullable AS [Nullable]
FROM
sys.types AS st
INNER JOIN sys.schemas AS sst ON sst.schema_id = st.schema_id
LEFT OUTER JOIN sys.types AS baset ON baset.user_type_id = st.system_type_id and baset.user_type_id = baset.system_type_id
WHERE
(st.schema_id!=4 and st.system_type_id!=240 and st.user_type_id != st.system_type_id)
ORDER BY
[Schema] ASC,[Name] ASC


select
     convert(char(15),a.name) [user type]
     ,(select convert(varchar(10),b.name) 
       from systypes b 
       where b.type=a.type  
       having b.usertype = min(b.usertype))
     + case
when (select b.name from systypes b 
      where b.type=a.type  
      having b.usertype = min(b.usertype) )='char'
then '('+convert(varchar(10),a.length)+')'
end
     ,a.prec
     ,a.scale
FROM systypes a
WHERE accessrule != NULL
go
0

精彩评论

暂无评论...
验证码 换一张
取 消