sap-ase - 如何在 Sybase ASE 中查找列的默认值
问题描述
我们想在 Sybase ASE 中找到列的默认值。下面给出了 SQL 服务器的类似查询,我们希望 sybase 也一样。
SELECT COLUMN_DEFAULT from INFORMATION_SCHEMA.COLUMNS
解决方案
注意:从这个相关的问答中复制:
如何在 Sybase ASE 系统表中查找默认值...
- 如果列具有默认值,则syscolumns 中的关联记录将具有存储在cdefault列 中的非零值,即 syscolumns.cdefault > 0。
- 非零cdefault值是指向syscomments中存储有关默认信息的记录的指针,即syscolumns.cdefault = syscomments.id。
- 实际默认值以两种格式之一存储在syscomments.text列中,具体取决于默认值是a)内联定义为create/alter table命令的一部分,还是b)通过create default命令定义为独立默认值。
例子:
-- 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
从这里您应该能够根据syscomments.text列的格式和实际的默认值(即,它是数字吗?它是一个字符串,可能带有嵌入的空格?它是一个函数参考)解析出默认值,例如getdate() )。
推荐阅读
- python - 拆分和连接后,我没有找回所有的字符串
- php - 使用 phpmailer 库在 PHP 中 smtp connect() 失败
- julia - 如何在 Julia 中更改级别
- react-native - TypeError:当我在 createDrawerNavigator 中使用自己的组件作为 contentComponent 时,无法读取未定义的属性“默认”
- vue.js - 使用缩放插件在 chart.js 中获取当前缩放信息
- python - 执行我的自定义最大似然代码时出现意外行为。它跳转到未调用的函数
- vba - VBA - 如果将某些数字传递给另一个子,则溢出错误
- authentication - 如何在httpUnit中设置认证参数?
- java - oauth 2.0 没有弹簧启动
- postgresql - 在 Postgresql 中将数据复制到视图中的方法