• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • Last Modified:

How to declare a unique key constraint using mysql table editor?

Is it possible to declare a unique constraint on a column in MYSQL. and can this be done through the MYSQL table editor?
if not what is the correct syntax?
it is very critical for me to solve this right now.. please help..
Thank you,
0
Pavithra_S
Asked:
Pavithra_S
  • 6
  • 2
  • 2
  • +1
1 Solution
 
AncientFribCommented:
if the column already exists try:

alter table <TableName> change column <ColumnName> <NewColumnName> <type(int char etc)> PRIMARY KEY

Something like

alter table tbl_table1 change column column1 column1 int PRIMARY KEY

Can probably use UNIQUE instead of PRIMARY too.
0
 
HainKurtSr. System AnalystCommented:
here it is

ALTER TABLE Persons
ADD CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)
0
 
Pavithra_SAuthor Commented:
Thanks for the suggestion.. it helped!
I used something like
ALTER TABLE tablename
 ADD UNIQUE KEY  USING BTREE(`columnname`);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Pavithra_SAuthor Commented:
I am going to try the second suggestion too.. will let you know shortly.. thanks for all the help
0
 
Pavithra_SAuthor Commented:
is unique constraint different from unique key?
0
 
HainKurtSr. System AnalystCommented:
in MSSQL they are same ;)

http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/

when you create a unique constraintsm, it adds a unique index...
0
 
Zlatko KuzmanovskiprogrammerCommented:
Hi,

Please use this steps :
1) Start MySQL Administrator (your of course)
2) Goto Catalogs
3) Select your Database (Catalog)
4) In the "MySQL Table Editor" click on the small icon left of a column name
5) You can click on multiple column icons (to have multiple-column primary key)

Regards,
Zlatko.
0
 
Pavithra_SAuthor Commented:
Yes i noticed that we can have multiple column primary key.. but i need one primary key and the other column to have a unique key constraint...
i am working on MYSQL now.. but need to do thisin such a way that it easily migrates to MSSQL..
is there any particular suggestion with this regard?
once again thank u all for ur help!
0
 
Zlatko KuzmanovskiprogrammerCommented:
HI,
Here is the screen. Please look at the RED circles (steps).

Migration from MySQL to MSSQL will not be a problem.

(what is the tool are you using ?)

Regards,
Zlatko.
unique.JPG
0
 
Pavithra_SAuthor Commented:
THANKS!! Exactly what I was looking for.. not sure about the tool they are gonna use.. but trying to make sure it ready to migrate..
0
 
Pavithra_SAuthor Commented:
excellent help on this!  
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now