我正在尝试编写一个脚本来从旧的 MS SQL 6.5 中提取数据库,我偶然发现了检索用户类型
我有以下自定义类型:
我写了一个简单的脚本,其中一个基本名称从同一张表中查找:
select t1.name as name, t2.name as base_name, t1.length as length
from systypes t1, systypes t2
where t1.usertype > 100 and t2.usertype <= 100 and t1.type = t2.type
它返回我以下结果:
name base_name length
------------------------------ ------------------------------ ------
bitZ bit 1
tinyintZ tinyint 1
smallintZ smallint 2
intZ int 4
smalldatetimeZ smalldatetime 4
charZ_254 sysname 254
charZ_254 varchar 254
charZ_80 sysname 80
charZ_80 varchar 80
charZ_50 sysname 50
charZ_50 varchar 50
charZ_40 sysname 40
charZ_40 varchar 40
charZ_35 sysname 35
charZ_35 varchar 35
charZ_30 sysname 30
charZ_30 varchar 30
charZ_20 sysname 20
charZ_20 varchar 20
charZ_16 sysname 16
charZ_16 varchar 16
charZ_14 sysname 14
charZ_14 varchar 14
charZ_12 sysname 12
charZ_12 varchar 12
charZ_10 sysname 10
charZ_10 varchar 10
charZ_8 sysname 8
charZ_8 varchar 8
charZ_5 sysname 5
charZ_5 varchar 5
charZ_4 sysname 4
charZ_4 varchar 4
charZ_1 sysname 1
charZ_1 varchar 1
charZ_120 sysname 120
charZ_120 varchar 120
binZ_10 binary 10
binZ_10 timestamp 10
这里有2个问题:
- varchar 解析为两种类型,sysname 和 varchar,因为它们具有相同的基本类型。binZ_10 同样的问题
- 非 var char 作为非零长度返回
我可以使用哪个脚本来获得正确的 MS 输出?
这是原始表的片段:
select type, name from systypes order by type
type name
---- ------------------------------
. . .
39 charZ_80
39 sysname
39 varchar
45 binary
45 binZ_10
45 timestamp
47 char
. . .