MS SQL表字段自增相關的指令碼

2021-09-08 10:09:11 字數 555 閱讀 6114

--查詢表是否有自增欄位

select objectproperty(object_id('[表名]'), 'tablehasidentity')

--查詢表的自增欄位

select column_name

from   information_schema.columns

where  table_name = '[表名]'

and columnproperty(object_id('[表名]'), column_name, 'isidentity') = 1

--獲取sql自增列種子和增量 

select ident_seed('[表名]') as seed,

ident_incr('[表名]') as incr

--【檢視】表當前種子

dbcc checkident('[表名]', noreseed) 

--【查詢】表當前種子

select ident_current('[表名]')

--重置種子

dbcc checkident('[表名]', reseed, 50)

MS SQL表字段自增相關的指令碼

查詢表是否有自增欄位 select objectproperty object id 表名 tablehasidentity 查詢表的自增欄位 select column name from information schema.columns where table name 表名 and col...

oracle中如何指定表字段自增

背景介紹 sql server可以在int型別的字段後加上identity 1,1 該字段就會從1開始,按照 1的方式自增,將這個字段設定為主鍵,有利於我們進行資料的插入操作。mysql中可以使用 auto increment 即可。但是oracle有點麻煩,需要使用序列和觸發器達到目的。學校表 c...

SQL更改表字段為自增標識

下面是sql語句 刪除主鍵約束 declare constraint name varchar 200 select constraint name name from dbo.sysobjects where xtype pk and parent obj select id from dbo.s...