Solved

Are you supposed to apply the primary key to an IDENTITY column? Please elaborate.

Posted on 2013-02-07
2
223 Views
Last Modified: 2013-02-07
When creating  an IDENTITY column in  a table do you also apply a primary key to it?


Example:
CREATE TABLE HR.Employees(
EmployeeId INT IDENTITY(1000 ,2) NOT NULL
,etc…)
0
Comment
Question by:rhservan
[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
  • 2
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 38865555
Identity fields are almost always primary keys yes, as it guarantees uniqueness in a row, but it is not required.

In your above T-SQL, making EmployeID the identity field might not always work, if the client sees a scenario where they would want to manually change the id for whatever reason.   If that's the case, an identity field would be the primary key, the actual EmployeeID would be what's called a 'business key'.  Forms would always display business key, and the database is related via the identity field.

You'll have to feel them out on that one.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38865687
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 68
TSQL recursive CTE challenge... 8 34
Add a step to a system backup job 6 32
MS SQL Server select from Sub Table 14 41
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

763 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