摘要:[MSSQL] Systypes
===== 底下相關資料為網路轉貼資料僅供自己備忘用 ======
select * from sys.systypes
[name] → 資料類型:varchar、text、int、bit...etc
[xusertype] → 資料類型編號
34 : image
35 : text
36 : uniqueidentifier
48 : tinyint
52 : smallint
56 : int
58 : smalldatetime
59 : real
60 : money
61 : datetime
62 : float
98 : sql_variant
99 : ntext
104 : bit
106 : decimal
108 : numeric
122 : smallmoney
127 : bigint
165 : varbinary
167 : varchar
173 : binary
175 : char
189 : timestamp
231 : nvarchar
239 : nchar
231 : sysname
---------
查詢現有 TABLE 的資料屬性:
SELECT obj.name AS tableName,
clum.name AS columnsName,
clum.prec AS columnsLength,
clum.colorder AS columnsOrder,
sType.name + '' AS columnsType,
sType.xusertype + '' AS typeCode
FROM dbo.sysobjects AS obj INNER JOIN
dbo.syscolumns AS clum ON obj.id = clum.id INNER JOIN
dbo.systypes AS sType ON clum.xusertype = sType.xusertype
WHERE (obj.xtype = 'U')
/* xtype 的類型
S → 系統的東西
SQ →
IT →
D →
U → 自建的 Table
V → 自建的 View
PK → 各 Table 的 PK欄
UQ → 各 Table 的 Unique Key 欄
F → 各 Table 的 Foreign Key 欄
P → 自建的 Store Procedure
*/