12
返回列表 发新帖
楼主: orcal

[精华] 删除表的记录以后,如何使新记录的编号仍然从1开始

[复制链接]
论坛徽章:
3
奥运会纪念徽章:射箭
日期:2008-09-10 09:49:45生肖徽章2007版:鸡
日期:2009-06-15 10:24:482010广州亚运会纪念徽章:乒乓球
日期:2010-10-26 22:22:34
11#
发表于 2007-3-10 12:22 | 只看该作者
zhuzhichao
炎龙骑士   的方法果然好用-

/*
create table t_t1
(id int identity(1,1),
name varchar(10)
)

insert into t_t1 select 'xx1'
union all select 'xx1'
union all select 'xx1'
union all select 'xx1'
union all select 'xx1'
union all select 'xx1'
union all select 'xx1'
*/

select * from t_t1

--truncate table t_t1    --truncate table 你的表名 --這樣不但將數據刪除,而且可以重新置位identity屬性的字段。

delete from t_t1
dbcc checkident(t_t1,reseed,0) --dbcc checkident(你的表名,reseed,0) --重新置位identity屬性的字段,讓其下個值從1開始

insert into t_t1 select 'xx1'
union all select 'xx1'
union all select 'xx1'

select * from t_t1

---运行结果---
id          name      
----------- ----------
1           xx1
2           xx1
3           xx1

(3 row(s) affected)


id          name      
----------- ----------
1           xx1
2           xx1
3           xx1

(3 row(s) affected)

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表