SQL Server - Violation of PRIMARY KEY constraint 'PK_XX_XXXXX’ and constraint not found
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
We have application where API communicate with SQL Server database and get & set data thru stored procedure.
While saving data in production server, we are getting error (Custom error handling) in application as follows
‘Data for below tabs are not saved successfully, please review data and save
Dynamic : Violation of PRIMARY KEY constraint 'PK_XX_XXXXXX’
Now to check the issue, we were searching for given constrain name in database using below, but surprisingly, we do not found any such constraint, so now how to identify the table which causes this error
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('PRIMARY_KEY_CONSTRAINT')
order by 1
Is there any way to get the table name linked to given primary key?
add a comment |
We have application where API communicate with SQL Server database and get & set data thru stored procedure.
While saving data in production server, we are getting error (Custom error handling) in application as follows
‘Data for below tabs are not saved successfully, please review data and save
Dynamic : Violation of PRIMARY KEY constraint 'PK_XX_XXXXXX’
Now to check the issue, we were searching for given constrain name in database using below, but surprisingly, we do not found any such constraint, so now how to identify the table which causes this error
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('PRIMARY_KEY_CONSTRAINT')
order by 1
Is there any way to get the table name linked to given primary key?
add a comment |
We have application where API communicate with SQL Server database and get & set data thru stored procedure.
While saving data in production server, we are getting error (Custom error handling) in application as follows
‘Data for below tabs are not saved successfully, please review data and save
Dynamic : Violation of PRIMARY KEY constraint 'PK_XX_XXXXXX’
Now to check the issue, we were searching for given constrain name in database using below, but surprisingly, we do not found any such constraint, so now how to identify the table which causes this error
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('PRIMARY_KEY_CONSTRAINT')
order by 1
Is there any way to get the table name linked to given primary key?
We have application where API communicate with SQL Server database and get & set data thru stored procedure.
While saving data in production server, we are getting error (Custom error handling) in application as follows
‘Data for below tabs are not saved successfully, please review data and save
Dynamic : Violation of PRIMARY KEY constraint 'PK_XX_XXXXXX’
Now to check the issue, we were searching for given constrain name in database using below, but surprisingly, we do not found any such constraint, so now how to identify the table which causes this error
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('PRIMARY_KEY_CONSTRAINT')
order by 1
Is there any way to get the table name linked to given primary key?
edited Nov 15 '18 at 14:02
Sami
9,40331244
9,40331244
asked Nov 15 '18 at 13:50
Manish JoisarManish Joisar
212316
212316
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Use the INFORMATION_SCHEMA views...
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
WHERE CONSTRAINT_NAME = 'PK_XX_XXXXXX'
1
It's aVIEWnot a table
– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
|
show 1 more comment
There was issue with how application shows error text, somehow it was truncated and only half of the constraint name was displayed.
Client gave specific scenario to reproduce the error and then i found the exact table name and its primary key name.
Thanks all for your help.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320956%2fsql-server-violation-of-primary-key-constraint-pk-xx-xxxxx-and-constraint-no%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the INFORMATION_SCHEMA views...
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
WHERE CONSTRAINT_NAME = 'PK_XX_XXXXXX'
1
It's aVIEWnot a table
– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
|
show 1 more comment
Use the INFORMATION_SCHEMA views...
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
WHERE CONSTRAINT_NAME = 'PK_XX_XXXXXX'
1
It's aVIEWnot a table
– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
|
show 1 more comment
Use the INFORMATION_SCHEMA views...
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
WHERE CONSTRAINT_NAME = 'PK_XX_XXXXXX'
Use the INFORMATION_SCHEMA views...
SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
WHERE CONSTRAINT_NAME = 'PK_XX_XXXXXX'
edited Nov 15 '18 at 15:01
answered Nov 15 '18 at 13:56
AllumearzAllumearz
1996
1996
1
It's aVIEWnot a table
– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
|
show 1 more comment
1
It's aVIEWnot a table
– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
1
1
It's a
VIEW not a table– Sami
Nov 15 '18 at 13:58
It's a
VIEW not a table– Sami
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
This is a great example of why a constraint is a first-class object.
– nicomp
Nov 15 '18 at 13:58
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Allumeraz, Thanks for your reply, no table found with given primary constraint name
– Manish Joisar
Nov 19 '18 at 13:55
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hello Nicomp, Can you please explain more on this "This is a great example of why a constraint is a first-class object" ?
– Manish Joisar
Nov 19 '18 at 13:56
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
Hi Manish, can you post the Stored Procedure code? Could it be a table variable in the procedure with a Primary Key defined on it?
– Allumearz
Nov 19 '18 at 22:40
|
show 1 more comment
There was issue with how application shows error text, somehow it was truncated and only half of the constraint name was displayed.
Client gave specific scenario to reproduce the error and then i found the exact table name and its primary key name.
Thanks all for your help.
add a comment |
There was issue with how application shows error text, somehow it was truncated and only half of the constraint name was displayed.
Client gave specific scenario to reproduce the error and then i found the exact table name and its primary key name.
Thanks all for your help.
add a comment |
There was issue with how application shows error text, somehow it was truncated and only half of the constraint name was displayed.
Client gave specific scenario to reproduce the error and then i found the exact table name and its primary key name.
Thanks all for your help.
There was issue with how application shows error text, somehow it was truncated and only half of the constraint name was displayed.
Client gave specific scenario to reproduce the error and then i found the exact table name and its primary key name.
Thanks all for your help.
answered Nov 23 '18 at 14:17
Manish JoisarManish Joisar
212316
212316
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320956%2fsql-server-violation-of-primary-key-constraint-pk-xx-xxxxx-and-constraint-no%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown