0

I have run the following query to add unique constraint on column "name".

alter table mytable 
  add unique (name) 

Now I am trying to remove this constraint, I am getting errors.

Kindly give me a solution.

Thanks

ps. I am using SQL Server

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Muhammad Usman
  • 10,039
  • 22
  • 39
  • pl post the error – yuvi Oct 14 '16 at 08:50
  • Msg 3728, Level 16, State 1, Line 1 'name' is not a constraint. Msg 3727, Level 16, State 0, Line 1 Could not drop constraint. See previous errors. – Muhammad Usman Oct 14 '16 at 08:51
  • 1
    ALTER TABLE users DROP CONSTRAINT 'constraints_name' – yuvi Oct 14 '16 at 08:53
  • Incorrect syntax near 'constraints_name'. – Muhammad Usman Oct 14 '16 at 08:54
  • use without single qoutes as – yuvi Oct 14 '16 at 08:56
  • ALTER TABLE users DROP CONSTRAINT constraints_name – yuvi Oct 14 '16 at 08:56
  • Msg 3728, Level 16, State 1, Line 1 'constraints_name' is not a constraint. Msg 3727, Level 16, State 0, Line 1 Could not drop constraint. See previous errors. – Muhammad Usman Oct 14 '16 at 08:57
  • replace 'constraints_name' with ur constraint name – yuvi Oct 14 '16 at 08:58
  • ex: alter table #temp drop constraint uq_column_name – yuvi Oct 14 '16 at 08:59
  • thanks for your concern bro. let me explain you one more time I have a single table with 4 columns on of them is 'name'. I just ran this query to add unique constraint on name alter table mytable add unique (name) and this added the unique constraint to name column. now I am stuck. I am trying all you're telling me but I am still getting errors – Muhammad Usman Oct 14 '16 at 09:02
  • use this to get the constraint name and then drop it.in this quesry place the table name at the last select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='UNIQUE' and TABLE_NAME='yourtablename' – yuvi Oct 14 '16 at 09:04
  • Thanks a lot man. this worked for me. love you :p – Muhammad Usman Oct 14 '16 at 09:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/125683/discussion-between-yuvi-and-muhamamd-usman). – yuvi Oct 14 '16 at 09:18

1 Answers1

0

You can use

ALTER TABLE dbo.mytable DROP CONSTRAINT constraintname; 
Kannan Kandasamy
  • 13,405
  • 3
  • 25
  • 38