Reputation: 2156
I have a table with the following fields:
searchID ( I have set this as a primary key )
SearchText nvarchar(MAX)
.......
and so on
I want to make SearchText also as an additional primary field. How should this be done? Is that a good procedure to make two primary columns for a table?
Upvotes: 0
Views: 513
Reputation: 24903
It's impossible to have more than one primary key on one table and store unique values.
Your primary key must be as short as possible.
If you need to keep unique data in other column, you can create unique key on this column:
CREATE TABLE dbo.Table
(
SearchText nvarchar(MAX)NOT NULL,
CONSTRAINT AK_SearchText UNIQUE(SearchText)
);
Or with management studio:
Upvotes: 1
Reputation: 3591
You can create composite key as below
create table myTable
(
SearchId int not null,
SearchText nvharchar not null
) GO
-- Add Constraint
ALTER TABLE myTable
ADD CONSTRAINT pk_myConstraint PRIMARY KEY (SearchId ,SearchText)
GO
Upvotes: 0