Solved

make record unique in sql server 2012

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

746 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