identity(1,1)是指每插入一条语句时这个字段的值增1,
语法
IDENTITY [ ( seed , increment ) ]
参数
seed
装载到表中的第一个行所使用的值(标示种子)。
increment
增量值,该值被添加到前一个已装载的行的标识值上(标示增量)。
必须同时指定种子和增量,或者二者都不指定。如果二者都未指定,则取默认值 (1,1)。
例如:
create table WorkRoom
(WorkRoomID int not null identity(1,1) primary key,
WorkRoomName Varchar(50) null,
TeacherName Varchar(10) null,
WorkRoomManager Varchar(10) null,
WorkRoomPlan Varchar(max) null,
Purl Varchar(50) null,
Remarks Varchar(max) null,
)
修改s创建标示和删除标示:
ALTER TABLE TABLENAME DROP COLUMN ID
ALTER TABLE TABLENAME ADD ID int identity(1,1) not null
如何用sql语句去掉列的自增长(identity)
========================================
如何用sql语句去掉列的自增长(identity),取消标识命令:
**无法通过alter把现有自增字段改为非自增
比如alter table a alter id int,自增属性不会去掉
通过修改系统表可以做到(此法可能有不可预知的结果,慎之...)
sp_configure 'allow updates', 1
GO
reconfigure with override
GO
update syscolumns set colstat = colstat & 0x0000
where id=o b j e c t_id('表名') and name='字段名'
GO
sp_configure 'allow updates', 0
---------------------------------
--折中的办法
alter table a add xxx int
update a set xxx=id
alter table a drop column id
exec sp_rename 'xxx', 'id', 'column'
========================================
第一个方法是可以去掉,但以后可能会导致出问题,建议用第二个方法,我用的语句现在也贴出来,也许需要的朋友有些用处
删除表 zx_user 中字段 userid 的自增长属性方法:
//新建临时字段
alter table zx_user add useridtmp int null
//赋值
update zx_user set useridtmp =userid
//删除主键
alter table zx_user drop pk_zx_user
//删除字段
alter table zx_user drop column userid
//增加字段
alter table zx_user add userid int null
//把值还原回来
update zx_user set userid = useridtmp
//删除临时字段
alter table zx_user drop column useridtmp
//修改新建字段不为空
alter table zx_user alter column userid int not null
//健主键,多个字段做主键,用逗号隔开,比如primary key (userid,xxxxxx)
alter table zx_user add primary key (userid)
========================================
删除主键时候,不知道你主键名字,请用一下方法查询:
select * from syso b j e c ts where xtype='PK
语法
IDENTITY [ ( seed , increment ) ]
参数
seed
装载到表中的第一个行所使用的值(标示种子)。
increment
增量值,该值被添加到前一个已装载的行的标识值上(标示增量)。
必须同时指定种子和增量,或者二者都不指定。如果二者都未指定,则取默认值 (1,1)。
例如:
create table WorkRoom
(WorkRoomID int not null identity(1,1) primary key,
WorkRoomName Varchar(50) null,
TeacherName Varchar(10) null,
WorkRoomManager Varchar(10) null,
WorkRoomPlan Varchar(max) null,
Purl Varchar(50) null,
Remarks Varchar(max) null,
)
修改s创建标示和删除标示:
ALTER TABLE TABLENAME DROP COLUMN ID
ALTER TABLE TABLENAME ADD ID int identity(1,1) not null
如何用sql语句去掉列的自增长(identity)
========================================
如何用sql语句去掉列的自增长(identity),取消标识命令:
**无法通过alter把现有自增字段改为非自增
比如alter table a alter id int,自增属性不会去掉
通过修改系统表可以做到(此法可能有不可预知的结果,慎之...)
sp_configure 'allow updates', 1
GO
reconfigure with override
GO
update syscolumns set colstat = colstat & 0x0000
where id=o b j e c t_id('表名') and name='字段名'
GO
sp_configure 'allow updates', 0
---------------------------------
--折中的办法
alter table a add xxx int
update a set xxx=id
alter table a drop column id
exec sp_rename 'xxx', 'id', 'column'
========================================
第一个方法是可以去掉,但以后可能会导致出问题,建议用第二个方法,我用的语句现在也贴出来,也许需要的朋友有些用处
删除表 zx_user 中字段 userid 的自增长属性方法:
//新建临时字段
alter table zx_user add useridtmp int null
//赋值
update zx_user set useridtmp =userid
//删除主键
alter table zx_user drop pk_zx_user
//删除字段
alter table zx_user drop column userid
//增加字段
alter table zx_user add userid int null
//把值还原回来
update zx_user set userid = useridtmp
//删除临时字段
alter table zx_user drop column useridtmp
//修改新建字段不为空
alter table zx_user alter column userid int not null
//健主键,多个字段做主键,用逗号隔开,比如primary key (userid,xxxxxx)
alter table zx_user add primary key (userid)
========================================
删除主键时候,不知道你主键名字,请用一下方法查询:
select * from syso b j e c ts where xtype='PK
标签:
sql,自增长,删除
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“sql自增长设置与删除的深入分析”评论...
更新日志
2024年07月05日
2024年07月05日
- 关智斌.2005-MUSICK【英皇娱乐】【FLAC分轨】
- 任贤齐.2010-任贤齐创作集音乐旅行者【滚石】【WAV+CUE】
- dnf攻击属性怎么点亮
- 魔兽世界有哪些GM命令 魔兽世界GM命令大全介绍
- dnf攻速鞋怎么才算140
- 群星2012-Sampler发烧中的精选(国语)4辑[新世纪][WAV+CUE]
- [发烧人声]群星《发烧中的精选SAMPLERAUDIOPHILE》AMCD限量版[WAV+CUE]
- 中唱唱片群星《好歌珍藏-激情年代》2CD【WAV】
- 王韵婵.1996-需要【现代派】【WAV+CUE】
- 群星.2024-你就在我身边电影原声专辑【奔跑怪物】【FLAC分轨】
- 何映达.1990-孤独地拥有你【蓝与白】【WAV+CUE】
- dnf新鲜冒险奇闻有什么用
- dnf无色套是哪几件
- dnf旭旭宝宝红眼装备是什么搭配
- 陈思安2005-我无醉[华特][WAV+CUE]