-2

I wrote code like

ALTER TABLE [dbo].[Questions] 
ADD UNIQUE (Question);

But it shows error like

Column 'Question' in table 'Questions' is of a type that is invalid for use as a key column in an index.

Please help me..

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SURESH MOGUDALA
  • 35
  • 1
  • 12

2 Answers2

1
ALTER TABLE [dbo].[Questions] ADD constraint q_pk UNIQUE (Question);

See here for documentation

vhadalgi
  • 7,027
  • 6
  • 38
  • 67
0

ALTER TABLE [dbo].[Questions] ADD UNIQUE (Question); Column 'Question' in table 'Questions' is of a type that is invalid for use as a key column in an index.

In Question-column of table Questions should not be 'nvarchar(MAX)' but i have 
given before table schema question as nvarchar(max) so it gives such error

Questions' is of a type that is invalid for use as a key column in an index.

I have changed to varchar(255). Its working fine. Thanks.

SURESH MOGUDALA
  • 35
  • 1
  • 12