当前位置: 代码迷 >> Sql Server >> 在SQL Server 2000中怎么知道自动增长列的定义(比如初始值是多少?每次增加多少?),以及计算列的定义
  详细解决方案

在SQL Server 2000中怎么知道自动增长列的定义(比如初始值是多少?每次增加多少?),以及计算列的定义

热度:11   发布时间:2016-04-27 11:28:49.0
在SQL Server 2000中如何知道自动增长列的定义(比如初始值是多少?每次增加多少?),以及计算列的定义?
在SQL Server 2005中可以通过查询sys.identity_columns和sys.computed_columns系统目录视图得到自动增长列(也称标识列)和计算列的定义,可是在SQL Server 2000中没有这些视图,请问有没有什么替代方案???
  散尽可用分,在线跪求答案(凡接分者一律没分)^-^


------解决方案--------------------
IDENT_CURRENT
返回为任何会话和任何作用域中的指定表最后生成的标识值。 

语法
IDENT_CURRENT('table_name')


IDENT_INCR
返回增量值(返回形式为 numeric(@@MAXPRECISION,0)),该值是在带有标识列的表或视图中创建标识列时指定的。

语法
IDENT_INCR ( 'table_or_view' ) 


IDENT_SEED
返回种子值(返回形式为 numeric(@@MAXPRECISION,0)),该值是在带有标识列的表或视图中创建标识列时指定的。

语法
IDENT_SEED ( 'table_or_view' ) 

------解决方案--------------------
SQL code
create table test001 (id int IDENTITY(1,1),a int ,b numeric(10,2),c as a*b)goselect name,case when colstat &1=1 then '标志列' when colstat &4=4 then '计算列' else '一般列' end as 属性 from syscolumnswhere id=object_id('test001')--结果name                                                                                                                             属性     -------------------------------------------------------- ------ id                                                                                                                               标志列a                                                                                                                                一般列b                                                                                                                                一般列c                                                                                                                                计算列(所影响的行数为 4 行)
------解决方案--------------------
SQL code
--> 2000中模拟2005的sys.identity_columnsselect    object_name(id) as table_name,    ident_seed(object_name(id)) as seed_value,    ident_incr(object_name(id)) as increment_value,    ident_current(object_name(id)) as last_value,    *from syscolumnswhere objectproperty(id, 'IsUserTable') = 1 and status = 0x80--> 2000中模拟2005的sys.computed_columnsselect    object_name(a.id) as table_name,    b.text as definition,    a.*from syscolumns a join syscomments b on a.id = b.idwhere objectproperty(a.id, 'IsUserTable') = 1 and a.iscomputed = 1
------解决方案--------------------
SQL code
create table T(ID int identity,Col1 int,Col2 as ID+COl1)goselect    Name as 列名,    case when iscomputed=1 then '计算列' when status=0x80 then '标识列' else '一般列' end as 属性from     syscolumnswhere    ID=object_id('T')列名                                                                                                                               属性     -------------------------------------------------------- ------ ID                                                                                                                               标识列Col1                                                                                                                             一般列Col2                                                                                                                             计算列(所影响的行数为 3 行)
------解决方案--------------------
SQL code
/*谢谢1楼和3楼以及2楼精神上的支持,那如何得到计算列的定义呢?比如在三楼举的例子中如何知道列b是被定义为numeric(10,2)的呢?*/--> 参考。未尽之处自己改或加 when...select    table_name = object_name(a.id),    column_name = a.name,    data_type_definition    = b.name +         case            when b.name in ('char', 'varchar', 'binary','varbinary') then '('+ltrim(a.length)+')'            when b.name in ('nchar', 'nvarchar') then '('+ltrim(a.length/2)+')'            when b.name in ('decimal','numeric','float','real') then '('+ltrim(a.xprec)+','+ltrim(a.xscale)+')'            else ''        endfrom syscolumns a join systypes b on a.xusertype = b.xusertype
  相关解决方案