User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 425,815 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,116 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1155 | Replies: 3
Reply
Join Date: May 2008
Posts: 13
Reputation: vinaya is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
vinaya vinaya is offline Offline
Newbie Poster

can u please tel how to make a particular column unique

  #1  
May 27th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: can u please tel how to make a particular column unique

  #2  
May 27th, 2008
Originally Posted by vinaya View Post
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.
Reply With Quote  
Join Date: May 2008
Posts: 13
Reputation: vinaya is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
vinaya vinaya is offline Offline
Newbie Poster

Re: can u please tel how to make a particular column unique

  #3  
May 28th, 2008
Originally Posted by tesuji View Post
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)
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: can u please tel how to make a particular column unique

  #4  
May 28th, 2008
Originally Posted by vinaya View Post
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:
  1. 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
Last edited by tesuji : May 28th, 2008 at 8:54 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 4:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC