TRUNCATE TABLE name 
Truncate是一个能够快速清空资料表内所有资料的SQL语法。并且能针对具有自动递增值的字段,做计数重置归零重新计算的作用。

由于在SQL-SERVER中,自增列属性不能直接修改,但可以通过以下方式变向实现

1、如果仅仅是指定值插入,可用以下语句,临时取消

SET IDENTITY_INSERT TableName ON
INSERT INTO tableName(xx,xx) values(xx,xx)
SET IDENTITY_INSERT TableName OFF

2、新增一列,删除自增列,修改改列名

alter table a add xxx int
update a set xxx=id
alter table a drop column id
exec sp_rename 'xxx', 'id', 'column'

3、通过修改系统关于该表的列属性,该方法使用不当将可能引起其它不可预料的错误

sp_configure 'allow update',1
reconfigure with override
go
update syscolumns set colstat=0 where colstat=1 and id=object_id('tablename')
go
sp_configure 'allow update',0
reconfigure with override

由于在SQL-SERVER中,自增列属性不能直接修改,但可以通过以下方式变向实现

1、如果仅仅是指定值插入,可用以下语句,临时取消

SET IDENTITY_INSERT TableName ON
INSERT INTO tableName(xx,xx) values(xx,xx)
SET IDENTITY_INSERT TableName OFF

2、新增一列,删除自增列,修改改列名

alter table a add xxx int
update a set xxx=id
alter table a drop column id
exec sp_rename 'xxx', 'id', 'column'

3、通过修改系统关于该表的列属性,该方法使用不当将可能引起其它不可预料的错误

sp_configure 'allow update',1
reconfigure with override
go
update syscolumns set colstat=0 where colstat=1 and id=object_id('tablename')
go
sp_configure 'allow update',0
reconfigure with override

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-06-26
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
猜你喜欢
  • 2021-04-07
  • 2022-12-23
  • 2021-10-27
  • 2021-05-17
  • 2022-12-23
  • 2021-12-31
相关资源
相似解决方案