All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Delphi图像化的导航界面
ASP.NET技巧:用MasterPage,代替,PageBase_.net资料_编程技术
基于AJAX技术的DataGrid控件编程_[Asp.Net教程]
php+mysq 修改用户密码(用password加密)_[PHP教程]
利用XMLHTTP无刷新添加数据之Get篇_[XML教程]
使用PHP开发网站过程中你注意到这些安全知识了吗?_[PHP教程]
动态网页技术PHP程序中包含文件问题_php资料_编程技术
手把手教你制作vs2005装饰_[Asp.Net教程]
PHP和AJAX打造高级RSS聚合器_php资料_编程技术
Visual C++ 6.0教程:控制结构之分支结构
Reading number is top 10 pictures
机器人也有性生活吗?
Fan bingbing black wings for platform and DanLuoWang believes beauty2
南昌铁路局攸县车站125户铁路职工微利房终成骗局
Is said to be a Chinese female artist fame explicit pictures before2
The money of more than 100 countries and regions9
A beautiful girl to bud3
贩卖儿童者必须判死刑
这还能睡得着?
China telecom 114 spokesman MeiYanXu2
Li Zongrui hunting video screenshots1
Download software ranking
dreamweaver8中文版
Sora aoi‘s film--Lust fan wall
尖东毒玫瑰B
WebService在.NET中的实战应用教学视频 → 第1集
Sora aoi - one of more PK
天龙八部十二宫服务端
传奇私服架设教程-chm
Sora aoi 120 minutes
豪门浪荡史
Unix video tutorial20
delv published in(发表于) 2013/12/30 4:36:57 Edit(编辑)
Sql,Server2005_mssql学习_编程技术

Sql,Server2005_mssql学习_编程技术

Sql Server2005_mssql学习_编程技术-你的首页-uuhomepage.com


--> Title : 自增列重複與不連續







--> Author : wufeng4552







--> Date : 2009-11-13 08:31:12















--自增列通常在以下幾種情況而導致不連續







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--1插入失敗自動回滾







insert tb([name]) select 'A'







insert tb([name]) select 'A'







/*







錯誤原因







訊息2627,層級14,狀態1,行4







違反UNIQUE KEY 條件約束'UQ__tb__6B79F03D'。無法在物件'dbo.tb' 中插入重複的索引鍵。







陳述式已經結束。







*/







insert tb([name]) select 'B'







select * from tb







-->查詢結果







/*







(1 個資料列受到影響)







ID name







----------- ----------







0 A







2 B







(2 個資料列受到影響)







*/







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--2手動回滾







insert tb([name]) select 'B'







begin tran







insert tb([name]) select 'A'







rollback tran







insert tb([name]) select 'C'







select * from tb







-->查詢結果







/*







ID name







----------- ----------







0 B







2 C







(2 個資料列受到影響)







*/







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--3重置種子







insert tb([name]) select 'B'







dbcc checkident(tb,reseed,2)







insert tb([name]) select 'C'







insert tb([name]) select 'D'







select * from tb







-->查詢結果







/*







ID name







----------- ----------







0 B







3 C







4 D







(3 個資料列受到影響)*/







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--4刪除







insert tb([name]) select 'B'







insert tb([name]) select 'C'







delete tb where [name]='C'







insert tb([name]) select 'D'







select * from tb







-->查詢結果







/*







ID name







----------- ----------







0 B







2 D







(2 個資料列受到影響)







*/















--自增列通常在以下幾種情況而導致重複







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--1手動插入







insert tb([name]) select 'B'







insert tb([name]) select 'C'







set identity_insert tb on







insert tb(id,[name]) select 1,'D'







set identity_insert tb off







select * from tb







-->查詢結果







/*







ID name







----------- ----------







0 B







1 C







1 D







(3 個資料列受到影響)







*/







if object_id('tb')is not null drop table tb







go







create table tb(ID int identity(0,1),name varchar(10)unique)







--2種子重置







insert tb([name]) select 'B'







dbcc checkident(tb,reseed,-1)







insert tb([name]) select 'C'







select * from tb







-->查詢結果







/*







ID name







----------- ----------







0 B







0 C















(2 個資料列受到影響)







*/





















添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.