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.

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.

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)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.