Nepethya Rana

Nepethya Rana

  • NA
  • 335
  • 145.9k

How to store same name when name column is PK

Aug 27 2016 1:41 PM
In one of interview i have been asked this question.
 
1) The database fails to store 2 employees that have the same name. Do not sacrifice the usage of the primary key index seek for searching by name. 
 
How can i solve this problem?  
 
CREATE TABLE dbo.employees
(
uniqueEmployeesId int NOT NULL IDENTITY (1, 1),
name varchar(10) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL,
CONSTRAINT PK_employees PRIMARY KEY CLUSTERED (  name  )
In this same schema there is another question 
 
2) The search is failing to find employees with names longer than 10 characters.
 
foreach (string name in namesToSearch)
{
nameParam = name;
//search for employees by name
queries.Add(from e in context.employees
where e.name == nameParam
select e);
}

Answers (2)