Solved

make record unique in sql server 2012

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

Independent Software Vendors: 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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

730 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