如何更改标识规范的表是标识 SQL Server [英] How to Alter a table for Identity Specification is identity SQL Server

查看:80
本文介绍了如何更改标识规范的表是标识 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不工作

ALTER TABLE ProductInProduct ALTER COLUMN Id KEY IDENTITY (1, 1);

检查图片

我有一个表 ProductInProduct 想要它的 id 应该是唯一的..

I have a table ProductInProduct is want its id should be Unique..

推荐答案

不能将现有列转换"为 IDENTITY 列 - 您必须创建一个新列INT IDENTITY:

You cannot "convert" an existing column into an IDENTITY column - you will have to create a new column as INT IDENTITY:

ALTER TABLE ProductInProduct 
ADD NewId INT IDENTITY (1, 1);

更新:

好的,所以一种将现有列转换为IDENTITY的方法.如果你绝对需要这个 - 查看 Martin Smith 的回复,其中包含所有血腥细节.

OK, so there is a way of converting an existing column to IDENTITY. If you absolutely need this - check out this response by Martin Smith with all the gory details.

这篇关于如何更改标识规范的表是标识 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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