如何为sql表中的主键列赋予唯一值 [英] how to give unique values to primary key column in an sql table

查看:312
本文介绍了如何为sql表中的主键列赋予唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是sql server的新手,我创建了一个名为tour package的表,其列如下所示

id

标题

描述

图片



这里id是主键列它必须是唯一的。这里我无法创建主列标识列,以便在添加新记录时列自动具有唯一ID。任何人都可以告诉我如何在主键列上插入唯一值或告诉我如何使用sql查询制作主键列标识列。请帮助我。上帝保佑你。提前谢谢你

解决方案

我不知道设置有什么问题你桌上的 IDENTITY 。但另外,您可以尝试在表的ID列中插入 MAX(ID)+ 1 。这将是独一无二的。



- Amy


你应该能够创建一个具有自动增量主键的表,请参阅:例如:了解SQL Server中的自动增量 [ ^ ]。


看看这个:

如何改变列到标识 [ ^ ]

Hi,

I am new to sql server and i have created a table named tour package with columns as shown below
id
heading
description
image

Here id is a primary key column and it has to be unique.Here i was unable to make the primary column identity column so that column will have unique id automatically as new records are added.Can anyone tell me how to insert unique values onto primary key column or tell me how to make primary key column identity column using sql query.Please help me.God bless you.Thank you in advance

解决方案

I don't know what is the problem with setting the IDENTITY to your table. But alternatively, you can try inserting MAX(ID) + 1 in ID Column of your table. That'll be unique.

--Amy


You should be able to create a table with auto increment primary key, see, for instance: "Understanding Auto Increment in SQL Server"[^].


Check this out:
how-to-alter-column-to-identity[^]


这篇关于如何为sql表中的主键列赋予唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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