Question

SQL STATEMENT TO CHANGE COLUMN VALUE!

Asked by: judsonmusic

I have a table called PK_members with a column names Unique Key set to false.

I need an SQL statement that will cahnge it to true

How can I do this?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-01-11 at 19:05:46ID22120051
Tags

column

,

sql

,

change

,

value

Topics

MySQL Server

,

SQL Query Syntax

,

MS SQL Server

Participating Experts
8
Points
500
Comments
32

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. which unique key should be used as PK?
    Hi experts, i have a table with two columns: name, id. both are unique, so, how do i assign pk? i know i can pick any of them, but there are two other tables which refer to each of them as FK. so, how to handle case like this? thanks.
  2. PK
    I have a table hat Iw ant to make two columns Primary key. How do I implement that. Her is my table structure: Name Null? Type ----------------------------------------- -------- ---------------------------- RMSG_KEY ...
  3. Junction table - PK - unique index
    Hello, I have a junction table with composite PK on 3 fields... [fldA], [fldB], [fldC] I also need values to be unique across 4 values... [fldA], [fldB], [fldC], [fldD] I cant add the [fldD] column to the pk cause then 2 records could have the same data for [fldA], [fldB], [...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: anokun7Posted on 2007-01-11 at 19:13:04ID: 18298771

Update table PK_members set <column_name> = 'true' where <column_name> = 'false';

Anoop

 

by: judsonmusicPosted on 2007-01-11 at 19:21:40ID: 18298795

This table is actually an index of a table.

I get this error when trying to so the command

Incorrect syntax near the keyword 'table'.

Update table PK_members set <column_name> = 'true' where <column_name> = 'false';
 
 
How can I just create and index that will set the column Unique key to true

 

by: QPRPosted on 2007-01-11 at 19:23:45ID: 18298817

or if you mean alter a table to add a constraint?

ALTER TABLE Names
ADD CONSTRAINT UniqueValues
UNIQUE (names);

 

by: QPRPosted on 2007-01-11 at 19:24:53ID: 18298822

that should be

ALTER TABLE PK_members
ADD CONSTRAINT UniqueValues
UNIQUE (names);

 

by: anokun7Posted on 2007-01-11 at 19:28:59ID: 18298839

Did you want to modify the table definition or update some values in the table column?

In my query, did you run it with the right column name, I did not get your column name. You can find it by running:

desc PK_members

 

by: GokulmPosted on 2007-01-11 at 19:31:16ID: 18298847

You are saying that PK_members is a index to some table. Are you intending to update the index or the table field. You cannot change the value of a field in index. It will be based on the value in the table.

 

by: judsonmusicPosted on 2007-01-11 at 19:32:39ID: 18298845

Let me clarify

I need to alter and INDEX called PK_members

there is a cloumn called Unique key that is currently set to false.

I need to cahnge it to true

 

by: judsonmusicPosted on 2007-01-11 at 19:37:00ID: 18298864

how can I make the index a unique key???

 

by: Raynard7Posted on 2007-01-11 at 19:37:01ID: 18298872

Hi,

You have posted this in the mysql and mssql areas - which db are you using?

Additionally - if this is the primary key you can not set it to be non unique.

If this is a key and not a primary key - it however is unique you could do

in mysql - to change from a non unique key to a unique one you need to drop the index - then add it again as "unique" including the definition again for the keys involved.

alter table `schemaName`.`tableName` drop key `PK_members`, add Unique  `PK_members` ( `Column1`,`Column2` )

 

by: GokulmPosted on 2007-01-11 at 19:39:45ID: 18298879

You can create a UNIQUE index by using
CREATE UNIQUE <CLUSTERED/NONCLUSTERED> INDEX index_name
ON table_name.col_name

 

by: judsonmusicPosted on 2007-01-11 at 19:42:18ID: 18298881

Windows SQL server

It is on godaddy.com

it defaults the Unique key column to FALSE and there is no way to change it without making a statement.

 

by: Raynard7Posted on 2007-01-11 at 19:43:27ID: 18298898

Same principle applies,

Firstly drop the index - then run the command that Gokulm gave.

 

by: kosturdurPosted on 2007-01-11 at 19:43:48ID: 18298900

Hi judsonmusic,


SET NOCOUNT OFF
USE MyDatabase
IF EXISTS (SELECT name FROM sysindexes
      WHERE name = 'PK_members')
   DROP INDEX MyTable.PK_members
GO
USE MyDatabase
CREATE UNIQUE INDEX PK_members
   ON MyTable (MyColumn)
GO

Kosturdur

 

by: teddysetiawanPosted on 2007-01-11 at 19:44:17ID: 18298903

If you want to make it as a unique key ,
you must clean up the data first from any duplicate , then you can alter the table successfully

 

by: vadimrapp1Posted on 2007-01-11 at 19:49:20ID: 18298918

DROP INDEX PK_members
CREATE UNIQUE INDEX PK_MEMBERS ON MyTable(MyColumn)

==================

You will need to replace MyTable with the name of the table the index is on, and MyColumn with the name(s) of the column(s) the index is on.

If you have Enterprise Manager, you can open the index (by design Table, then Indexes/Keys), check the checkbox "Create UNIQUE" for your index, save, and it will become unique.

 

by: kosturdurPosted on 2007-01-11 at 19:49:57ID: 18298921

sorry

Hi judsonmusic,

*******************
SET NOCOUNT OFF
USE MyDatabase
IF EXISTS (SELECT name FROM sysindexes
      WHERE name = 'MyIndexName')
   DROP INDEX MyTable.MyIndexName
GO
USE MyDatabase
CREATE UNIQUE INDEX MyIndexName
   ON MyTable (MyColumn)
GO
************************
now ok

Kosturdur

 

by: judsonmusicPosted on 2007-01-11 at 19:56:31ID: 18298934

I deleted the indexmanually and did this:


CREATE UNIQUE INDEX PK_members
 ON members (ID)
GO

The problem is that there are 2 columns in the index, one called unique, which is set to true, and one called unique key, which is set to false. I need to change unique key to true!

Thanks

 

by: Raynard7Posted on 2007-01-11 at 19:59:45ID: 18298960

i guess a better question is why?
why do you need one set but not the other?

 

by: judsonmusicPosted on 2007-01-11 at 20:01:09ID: 18298958

these are the columns:

Index /Columns /Primary /Unique /Clustered /Ignore dup. keys /Unique key /Stats /no recomp. /Fill factor /File group/PK_members id

they are set to(in order)

  True  /True  /True  /False /False  /False  /0  /PRIMARY

I need to change the Unique key column to TRUE

 

by: kosturdurPosted on 2007-01-11 at 20:23:13ID: 18299052

Update PK_members set Unique key = 'true' where Unique key = 'false';

 

by: judsonmusicPosted on 2007-01-11 at 20:29:24ID: 18299067

Incorrect syntax near the keyword 'Unique'.

Update PK_members set Unique key = 'true' where Unique key = 'false';

 

by: kosturdurPosted on 2007-01-11 at 20:35:45ID: 18299086

What's your Column's name? I thing it is "UniqueKey" or "Unique_Key" please chance  the "Unique key" part whit the name of your Column.

Update PK_members set Unique key = 'true' where Unique key = 'false';

For example;

Update PK_members set Uniquekey = 'true' where Uniquekey = 'false';


with no spaces(blanks)

 

by: kosturdurPosted on 2007-01-11 at 20:48:15ID: 18299119

ok try this

Update PK_members set PK_members.[Unique key] = 'true' where PK_members.[Unique key] = 'false';

Kosturdur

 

by: GokulmPosted on 2007-01-11 at 20:50:36ID: 18299131

If you have space in the column name you might try using
Update PK_members set [Unique key] = 'true' where [Unique key] = 'false'

 

by: Raynard7Posted on 2007-01-11 at 20:51:21ID: 18299135

Since you are talking about an index an not about a table I don't believe that Kosturdur's approach will work.

Have you considered making this field the primary key? does this change the Unique Key value to true? alternatively make it a foreign key?

But again - I ask why do you need this? if you are hoping to achieve something there may be a better approach.

 

by: judsonmusicPosted on 2007-01-11 at 20:55:23ID: 18299141

I am using dreamweaver to develop a update record function and when I create a recordset it says please choose a table with a unique key.

 

by: Raynard7Posted on 2007-01-11 at 20:55:47ID: 18299151

i'd suggest that you add this as a primary key - not just a simple index

 

by: kosturdurPosted on 2007-01-11 at 21:03:19ID: 18299167

Defining a Primary Key
Define a primary key to enforce uniqueness for values entered in specified columns that do not allow nulls. If you define a primary key for a table in your database, you can relate that table to other tables, thus reducing the need for redundant data. A table can have only one primary key.  

To define a primary key

In Enterprise manager, in your database diagram or Table Designer, click the row selector for the database column you want to define as the primary key. If you want to select multiple columns, hold down the CTRL key while you click the row selectors for the other columns.

Right-click the row selector for the column and select Set Primary Key. A primary key index, named "PK_" followed by the table name, is automatically created; you can find it on the Indexes/Keys tab of the property pages.
Warning   If you want to redefine the primary key, any relationships to the existing primary key must be deleted before the new primary key can be created. A message will warn you that existing relationships will be automatically deleted as part of this process.

A primary key column is identified by a primary key symbol  in its row selector.

If a primary key consists of more than one column, duplicate values are allowed in one column, but each combination of values from all the columns in the primary key must be unique.

If you define a compound key, the order of columns in the primary key matches the order of columns as shown in the table in your diagram. However, you can change the order of columns after the primary key is created.

Kosturdur

 

by: vadimrapp1Posted on 2007-01-11 at 21:16:07ID: 18299206

Dear Experts,

in case you did not figure out yet - here are some tips, as I understand the situation.

judsonmusic has a hosting service on godaddy. Hosting service includes a database. The only access he/she has to the database is through the web-based control panel provided by godaddy.

At some place of the web interface, it allows to define an index for the table. The web interface to the index appears on the godaddy's control panel webpage as a table described in his post at 01/11/2007 08:01PM PST

So, when judsonmusic is asking how to change the table, he/she means not the table in the database, but the table in godaddy interface. One of the cells of that interface, obviously, is showing if the index is unique, and it's showing "no". The problem is how to make it so that that column will show "yes".

So it's a question not about the database, but rather about godaddy's hosting interface. There's no enterprise manager in this picture, abd obviously no database knowledge.

 

by: judsonmusicPosted on 2007-01-11 at 22:57:39ID: 18299414

vadimrapp1:

I accepted your answer due to the fact that you are correct, I basically have limited control over this situation.

I wound up deleteing everything and starting over. I already had the index set up and column ID as primary key. For some reason, Dreamweaver kept giving me an error about it saying that the recordset could not be created without a primary key on the table.

I uninstalled and re-installed dreamweaver and now it works. I want to aplogize to everyone for the wate of time and praise you for your answers.

Thanks

Judson   www.judsonmusic.com

 

by: dqmqPosted on 2007-01-11 at 22:57:46ID: 18299421

In that case, it might be more productive to call the godaddy service provider as it's not really and SQL Server question.

 

by: judsonmusicPosted on 2007-01-11 at 23:01:22ID: 18299424

They told me that they couldnt help me and that I would have to write a custom SQL to change it. They suck like that. :(

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...