简体   繁体   English

如何在Sybase中获取所有用户定义的数据类型?

[英]How to get all user defined datatypes in Sybase?

Could you please help me in finding all user defined datatypes in a sybase database. 你能帮我找一下sybase数据库中所有用户定义的数据类型吗?

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. 这些类型都是systypes,但它们没有明确描述为用户和系统类型。 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: 似乎所有系统类型都将accessrule设置为NULL,并且我的所有用户类型都将此设置为0,因此我使用了以下内容:

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 您可以在以下网址查看有关systypes表(以及其他相关表)的更多信息: 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. 由于sybase就像使用profiler的SQL服务器,我得到了这个查询。 If it does not work, use a profiler like tool for sybase, create a user defined type, and check the system tables it updates. 如果它不起作用,请使用类似于sybase的分析器工具,创建用户定义的类型,并检查它更新的系统表。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM