Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change an existing column to unique

Status
Not open for further replies.

yigalm

Technical User
Aug 16, 2001
42
US
Hi,

What is the syntax in SQL to change an existing column to be unique, but not create a new unique column?
 

The T-SQL syntax is as follows.

Alter Table Table_Name
Add Constraint Constraint_Name Unique(Column_Name)

Example:

Alter Table dbo.employees
Add constraint EmpNo_Unique Unique(EmpNo) Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
Use the SQL Alter Table command with Constraint and Unique.

Rick Cole
 
What is the constraint_name?

alter table pr2_users_values
add constraint <constraint name> unique (f_login);

This is what I have now, but what do I put for constraint_name?
 

Constraint_name is just a name for the constraint. It can be whatever you determine is best. Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
It says: Error 1061: Duplicate keyname 'F_Login'
 

Which version of SQL Server are you running?

Do you have a key, index or constraint with the same name? Try using a different name? Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
I am running MySQL.
When I say:
show create table pr2_users_values;

It lists this and all the other fields:
'F_Login' varchar(99) NOT NULL default ''

and at the bottom it says:
KEY 'F_Login' ('F_Login')
 
This is a MS SQL Server forum. The syntax may not always be compatible with MySQL. May I suggest moving your question to a MySQL forum or checking the MySQL website for the answer. Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top