【发布时间】:2020-09-01 06:27:27
【问题描述】:
我们想在 Sybase ASE 中找到列的默认值。下面给出了 SQL server 的类似查询,我们希望 sybase 也一样。
SELECT COLUMN_DEFAULT from INFORMATION_SCHEMA.COLUMNS
【问题讨论】:
标签: sap-ase
我们想在 Sybase ASE 中找到列的默认值。下面给出了 SQL server 的类似查询,我们希望 sybase 也一样。
SELECT COLUMN_DEFAULT from INFORMATION_SCHEMA.COLUMNS
【问题讨论】:
标签: sap-ase
注意:复制自related Q&A:
如何在 Sybase ASE 系统表中查找默认值...
例子:
-- inline default value of '0' assigned to column 'b'
create table t1 (a int, b int default 0 not null, c int)
go
-- standalone default named 'myzero' with default value of '0'; bound to column 'c'
create default myzero as 0
go
sp_bindefault myzero, 't1.c'
go
sp_help t1
go
...
Column_name ... Default_name
----------- ... --------------
a ... NULL
b ... t1_b_467529718 -- inline default
c ... myzero -- standalone default
...
-- contents of syscolumns.cdefault
select name, cdefault from syscolumns where id = object_id('t1') order by colid
go
name cdefault
---------- -----------
a 0
b 467529718
c 387529433
-- contents of syscomments.text
select id,text from syscomments where id in (467529718,387529433) order by id
go
id text
--------- ---------------------------
467529718 DEFAULT 0 -- inline default
387529433 create default myzero as 0 -- standalone default
-- pulling this all together:
select col.name, com.text
from syscolumns col,
syscomments com
where col.id = object_id('t1')
and col.cdefault = com.id
order by 1
go
name text
---------- ------------------------------
b DEFAULT 0 -- inline default
c create default myzero as 0 -- standalone default
从这里您应该能够根据 syscmets.text 列的格式和实际的默认值(即,它是数字吗?是字符串,可能有嵌入空间?它是一个函数引用,例如,getdate())。
【讨论】: