0

After creating the table i tried to specify the unique key constraint in sql server 2005 but its asking for the expression. I don't know what to give in that expression. can u please help me out in this.

thanx in advance.

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by tesuji
0

After creating the table i tried to specify the unique key constraint in sql server 2005 but its asking for the expression. I don't know what to give in that expression. can u please help me out in this.

thanx in advance.

pls post your create-table command and specify what column should be unique.

0

pls post your create-table command and specify what column should be unique.

I've not used create table command to create the table.
in SQl server management studio u've an option to create a table by right clicking on the table option u'l be providede with a new table option there i've created.

table UserList

user_id int (Primary key)
f_name varchar(50),
login varchar( I should make this field has unique)
address varchar(250)
email varchar(50)

0

I've not used create table command to create the table.
in SQl server management studio u've an option to create a table by right clicking on the table option u'l be providede with a new table option there i've created.

table UserList

user_id int (Primary key)
f_name varchar(50),
login varchar( I should make this field has unique)
address varchar(250)
email varchar(50)

If table already exists you can try this to make column login unique:

ALTER TABLE UserList ADD CONSTRAINT consName UNIQUE FOR login;

You must have owner-rights or sa / dba to this table. There are also some restrictions which depends on creation details, you obviously don't know. The constraint name consName must be a unique name within your database. If you want to remove such constraints you can write: ALTER TABLE UserList DROP CONSTRAINT consName ;

Further information: http://msdn.microsoft.com/en-us/library/ms190273.aspx

You can't add UNIQUE constraint if column already holds duplicate values.

If you have chance to re-create this table, simple write: create table UserList ( ..., login varchar(50) UNIQUE ...., ...); (but be careful not to lose data!)

krs,
tesu

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.