Solved

Primary Key Not Showing up in SQL Server Management Studio

Posted on 2013-01-30
6
692 Views
Last Modified: 2013-01-30
I am trying to set up replication.  When setting up the publisher there are several hundred tables that I cannot select because it states there are no primary keys.  However when I go into SQL Management Studio and try to create a primary key on one of those tables it will not create it because the primary key already exists.  When I view the keys for any of these tables or in design view there is no primary key shown yet it exists.  We have  a copy of this database in another environment and when I view the same table the primary keys are visible.  I thought it might be my SQL Management Studio so I tried it from several other workstations and still the same result.  I guess since it does not appear in SSMS the replication wizard thinks it does not exist as well.  Any idea what the issue might be?  Please advise.
0
Comment
Question by:Gary Harper
  • 2
  • 2
  • 2
6 Comments
 
LVL 42

Expert Comment

by:Eugene Z
ID: 38837831
if you had PK - Replication would take this table
you may pointed to wrong db;

check PK from SSMS or code

run sp_help yourtable
and sp_helpindex yourtablename

--can you post the pk creation error?
0
 
LVL 24

Expert Comment

by:DBAduck - Ben Miller
ID: 38837866
I would also check your permissions on those tables to ensure that you can View the meta data.  Typically that would be a granular permission, but it is possible that you cannot view the meta data for those tables.
0
 

Author Comment

by:Gary Harper
ID: 38838030
Here is the PK creation error.

/*
   Wednesday, January 30, 20138:33:01 PM
   User: food
   Server: LIMSDB1\LIMS34
   Database: food
   Application:
*/

'EFiles' table
- Unable to create index 'PK_EFiles'.  
The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'food.EFiles' and the index name 'PK_EFiles'. The duplicate key value is (Harran).
Could not create constraint. See previous errors.
The statement has been terminated.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 500 total points
ID: 38838038
OK, that is different.  This means that there is a key in the column being used for the Primary Key that is duplicated.  By definition, the Primary Key is UNIQUE and if there is a dup key, this is not Unique, so it will not create it.

Resolve the duplicate key and you will be able to create a Primary Key.
0
 

Author Comment

by:Gary Harper
ID: 38838085
Ok.  That is exactly the case.  Thank you.
0
 
LVL 42

Expert Comment

by:Eugene Z
ID: 38838097
it is cool that you liked my post: "can you post the pk creation error? " :)
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Job Hung 17 37
removing unwanted rows from an sql server ranked table 13 36
T-SQL to copy a database 37 66
SQL eating up memory? 16 42
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

726 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