在 SQL Server 中将 Identity 设置为打开或关闭 [英] Setting Identity to on or off in SQL server

查看:97
本文介绍了在 SQL Server 中将 Identity 设置为打开或关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将列的 Is Identity 属性设置为关闭,并在插入显式值后再次将其设置为打开.我已经编写了此查询:

I want to set Is Identity property of a column to off and after inserting an explicit value setting it to on again.I've written this query :

SET IDENTITY_INSERT Tbl_Cartoons OFF

虽然它执行成功,但表设计没有任何变化.请提出解决方案,这真的很重要.

Although it executes successfully ,nothing changes in the table design. Please suggest a solution ,It's really crucial.

推荐答案

您给出的所有行都是禁用标识,以便您可以将特定值插入标识列 - 通常这是一次性需要的例如移动数据.身份仍然在列上,只是没有被执行.从概念上讲,这类似于禁用和删除触发器之间的区别.

All the line you've given does is to disable the identity so that you can insert specific values into your identity column - usually this is needed for one-offs such as moving data around. The identity is still there on the column, its just not being acted upon. Conceptually this is similar to the difference between disabling and removing triggers.

从列中完全删除标识更难.问题涵盖了它,但基本的想法是您必须创建一个新列,复制数据,然后删除标识列.

To remove the identity from the column entirely is harder. The question covers it, but the basic idea is that you have to create a new column, copy the data over, then remove the identity column.

这篇关于在 SQL Server 中将 Identity 设置为打开或关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆