Solved

make record unique in sql server 2012

Posted on 2012-03-26
5
354 Views
Last Modified: 2012-03-28
In SQL server 2012, how do you make the record unique (something like in Access : Indexed - No duplicates) ? I click on the table - select design - but I am unsure what to do next.
Now, field is nvarchar(5) type .. How do you index it so no duplicates are allowed? uniqueidentifier ?  what does AllowNull stand for ? user must enter a value i.e field cant be empty?
Since I imported my table from access, I used to have ID autoinc field. Now in server it says its an int. is it still an autoinc field or something else ?
0
Comment
Question by:senad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 100 total points
ID: 37770055
you can use SQL UNIQUE Constraint in SQl server
refer
http://www.w3schools.com/sql/sql_unique.asp

also  ID that you hvae conevrted from access you need to give primary key set identity to increment by 1
refer
http://www.w3schools.com/sql/sql_primarykey.asp
0
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 300 total points
ID: 37770251
In case you want to achieve this in design mode only, then follow below steps:

Defining unique keys/indexes:

1. Right click on a table and selct "Design" to open the table in design view.
2. Right click anywhere in the design view and select "Indexes/Keys".
3. In the "Indexes/Keys" window opened, click on Add button to add a new index.
4. On the right hand side, choose the column(s) you want to include in the index/unique key.
5. Choose Type as either Index or Unique Key as required.

Defining Auto increment:
In the table design view, select the column to be made Identity (autoincrement), and in the properties box below, expand "Identity Specification" and choose Yes against "(Is Identity)" property.

Thanks,
Harish
0
 
LVL 22

Author Comment

by:senad
ID: 37770687
autoinc field - tried saving but changes is not permitted ?
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 100 total points
ID: 37774658
>>autoinc field - tried saving but changes is not permitted ?<<
That is because you are rebuilding the table and you have not allowed that to happen: You have the "Prevent saving changes that require table re-creation" setting in Tools | Options set to false.
0
 
LVL 22

Author Comment

by:senad
ID: 37775251
deleted and recreated the field. works ok ...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question