Wednesday, 25 September 2013

Difference between Primary Key and Unique Index in SQL Server

Difference between Primary Key and Unique Index in SQL Server

My company is currently in the process of rewriting an application that we
recently acquired. We chose to use ASP.net mvc4 to build this system as
well as using the Entity Framework as our ORM. The previous owner of the
company we acquired is very adamant that we use their old database and not
change anything about it so that clients can use our product concurrently
with the old system while we are developing the different modules.
I found out that the old table structures does not have a Primary key,
rather, it uses a Unique Index to serve as their primary key. Now when
using Entity framework I have tried to match their tables in structure but
have been unable to do so as the EF generates a Primary key instead of a
unique index.
When I contacted the previous owner, and explained it, he told me that
"the Unique key in every table is the Primary Key. They are synonyms to
each other."
I am still relatively new to database systems so I am not sure if this is
correct. Can anyone clarify this?
his table when dumped to SQL generates:
-- ----------------------------
-- Indexes structure for table AT_APSRANCD
-- ----------------------------
CREATE UNIQUE INDEX [ac_key] ON [dbo].[AT_APSRANCD]
([AC_Analysis_category] ASC, [AC_ANALYSI_CODE] ASC)
WITH (IGNORE_DUP_KEY = ON)
GO
however my system generates:
-- ----------------------------
-- Primary Key structure for table AT_APSRANCD
-- ----------------------------
ALTER TABLE [dbo].[AT_APSRANCD] ADD PRIMARY KEY ([AC_Analysis_category])
GO

No comments:

Post a Comment