创建一个表
create table demoTb
( ID int identity(1,1) primary key ,
name varchar (30)
) |
查看有没有自增列 有就返回YES
IF (( SELECT OBJECTPROPERTY( OBJECT_ID(N 'demoTb' ), 'TableHasIdentity' )) = 1)
PRINT 'Yes'
ELSE PRINT 'No'
|
如果想插入自增列的值就
declare @tableName varchar (250)
declare @sql nvarchar(1000)
select @tableName = 'demoTb'
select @sql = 'SET IDENTITY_INSERT ' +@tableName+ ' ON' + char (13)+ 'insert into demoTb(id,name) values(2,' 'wu' ')'
print @sql exec sp_executesql @sql
insert into demoTb(id, name ) values (1, 'wu' )
select * from demoTb
|
本文转自lpxxn博客园博客,原文链接:http://www.cnblogs.com/li-peng/archive/2013/01/11/2855883.html,如需转载请自行联系原作者