Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

make record unique in sql server 2012

Posted on 2012-03-26
5
Medium Priority
?
358 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 400 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 1200 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 400 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

636 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