本文介绍了如何在表中使用两个主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在sql server的一个表中,它包含一个主键,我想再使用一个列作为主键。但是我们只能使用一个主键。如何实现这个
If In a table in sql server it is containing one primary key and I want to use one more column as primary key.but we can use only one primary key for a table.How should we achieve this
推荐答案如果你想使用两列作为主键,那么使复合主键意味着将两列作为主键 if u want to use two column as primary key then make composite primary key means make two column as primary key
看一下下面显示如何创建复合主键的链接 在SQL Server中创建复合主键 [ ^ ] 如何在SQL Server 2008中创建复合主键 [ ^ ] SQL Server添加主键 [ ^ ] 复合主键 [ ^ ] Take a look at the below links that show how to create composite Primary keys Creating composite primary key in SQL Server[^] How to create composite primary key in SQL Server 2008[^] SQL Server Add Primary Key[^] Composite Primary Keys[^]
表中只能有一个主键。虽然,这并不意味着它应该只有一列。您可以使用两列作为主键。这是一个例子: You can have only one primary key in a table. Although, this does not mean that it should be only one column. You can use two columns as primary key. Here''s an example: CREATE TABLE SampleTable ( Key1 integer, Key2 integer, SomeOtherColumn nvarchar primary key (key1, key2) );
您可能还需要考虑唯一约束。
更多推荐
如何在表中使用两个主键
发布评论