且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为sql表中的主键列赋予唯一值

更新时间:2023-11-24 13:31:28

我不知道设置有什么问题你桌上的 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[^]