SQL 查詢表中是否存在自增列

2021-06-14 18:38:07 字數 1231 閱讀 4630

注:本文引自網路;放在這裡主要是坐下備份,也方便大家互相學習……;經本人試用,此法完全可行;

sql server如何判斷某列是否自增

---判斷table是否存在自增列(identity column):

declare @table_name varchar(60)

set @table_name = '';

if exists(select top 1 1 from sysobjects

where objectproperty(id, 'tablehasidentity') = 1

and upper(name) = upper(@table_name)

select 1

else select 0

-- or

if exists(select top 1 1 from sysobjects so

where so.xtype = 'u'

and upper(so.name) = upper(@table_name)

and exists(select top 1 1 from syscolumns sc

where sc.id = so.id

and columnproperty(sc.id, sc.name, 'isidentity') = 1

select 1

else select 0

declare @table_name varchar(60)

set @table_name = '';

select so.name table_name,                   --表名字

sc.name iden_column_name,             --自增欄位名字

ident_current(so.name) curr_value,    --自增字段當前值

ident_incr(so.name) incr_value,       --自增字段增長值

ident_seed(so.name) seed_value        --自增字段種子值

from sysobjects so 

inner join syscolumns sc

on so.id = sc.id

and columnproperty(sc.id, sc.name, 'isidentity') = 1

where upper(so.name) = upper(@table_name)

SQL查詢Access中某錶是否存在方法

access資料庫雖然功能單一,但的確是乙個小巧精幹的開發夥伴,我在多個專案中與它見面,為了探知access資料庫的本源,今天上網查了些資料。現總結歸納如下 在access資料庫中通過sql語句找到某一表是否存在的確是一件困難的事。幸好,access本身就有一些隱含的資料物件能夠儲存你庫中的資訊,今...

SQL查詢包含自增列的表名和列名

sqlserver自增列判斷 簡單的判斷語句 sql2000以上 if columnproperty object id tb col isidentity 1 print 自增列 else print 不是自增列 sql2000以上查詢所有自增列字段 select 表名 b.name,欄位名 a....

mysql查詢表是否存在

show databases select from information schema.tables where table schema 或者是 show tables 或者是 show tables like table name 可用來判斷表是否存在 database name 是指資料庫...