Home > Database > Mysql Tutorial > body text

SQL Server修改标识列方法 如自增列的批量化修改

WBOY
Release: 2016-06-07 18:05:37
Original
1191 people have browsed it

最近在运行系统时需要对所有服务器上数据结构进行批量修改某个字段的自增属性改成非自增

通过界面设计上是能手工操作的,无法达到我批量修改几千台服务器。
因为此了一个脚本来批量执行。
环境:redgate + mssql 2008 r2
以下代码根据自己的业务稍做修改即使用。
代码如下:
--允许对系统表进行更新
exec sp_configure 'allow updates',1
reconfigure with override
GO
--取消标识列标记
update syscolumns set colstat = 0 where id = object_id('tablename') and colstat = 1
GO
--插入id=8001-8003的行
--恢复标识列标记
update syscolumns set colstat = 1 where id = object_id('tablename') and name = '标识列名称'
--重新设置标识的起始值
DBCC CHECKIDENT (表名称, RESEED, 10003)
--禁止对系统表进行更新
exec sp_configure 'allow updates',0
reconfigure with override

还有很多批量操作的知识,
如批量检查索引是否准确
字段的长度是否一致
作业是否运行结果一致
服务是否同时启动
……
都需要批量来处理。
可参考我其他的文章获取其他批量操作的方法。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!