Solved

make record unique in sql server 2012

Posted on 2012-03-26
5
350 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now