Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do I alter table to remove unique field

Posted on 2013-11-04
9
Medium Priority
?
261 Views
Last Modified: 2013-11-08
SET QUOTED_IDENTIFIER ON
GO
I have the following table.  How do I alter the table to remove unique from field ViewName by iteself.

IDRoleApps and ViewName together is fine.


CREATE TABLE [dbo].[ViewName](
      [IDViewName] [bigint] IDENTITY(1,1) NOT NULL,
      [ViewName] [nvarchar](50) NOT NULL,
      [ViewType] [nvarchar](50) NOT NULL,
      [ViewDescription] [nvarchar](255) NOT NULL,
      [IDRolesApps] [bigint] NULL,
 CONSTRAINT [ViewName_PrimaryKey] PRIMARY KEY CLUSTERED
(
      [IDViewName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IDViewName] UNIQUE NONCLUSTERED
(
      [ViewName] ASC,
      [IDRolesApps] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED
(
      [ViewName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
0
Comment
Question by:goodk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39622976
It appears to be added as a Unique Index and without a name supplied by the code. I suspect it will have a system generated name which you will have to retrieve and  then use to drop the Indie (or possibly a constraint).


Kelvin
0
 

Author Comment

by:goodk
ID: 39623257
Hi Kelvin,

How do i find the unique index? and then how do i use it to alter the table to remove unique index from Viewname field?
0
 

Author Comment

by:goodk
ID: 39623264
Hi Kelvin,

How do i find the system generated name? and then how do i use it to alter the table to remove unique index from Viewname field?
0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39623267
Do you have access to the database itself via SSMS?
0
 

Author Comment

by:goodk
ID: 39623272
I am using MS sql server management studio and I can run queries on the sql db.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39623281
OK, open the table in design, right click in and empty part of the designer and choose Indexes.

Review those list - lick each in turn on the left and see which fields are included in the right hand panel. The names on the left are the Index (or constraint names). You can delete it there by selecting it and deleting or using the syntax

ALTER TABLE tablename DROP CONSTRAINT indexname

Kelvin
0
 

Author Comment

by:goodk
ID: 39623298
It is a shared db so can see the design but cannot interact or modify it.

Alter table commands would work.
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 2000 total points
ID: 39623309
OK, use the management studio to see the index as described above, then use the name in the statement supplied above.


Kelvin
0
 

Author Closing Comment

by:goodk
ID: 39634686
thanks
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question