Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Databases Programming Interviews:BtrieveClipperData ModelingData StructuresDatabase AdministrationDatabase Administrator (DBA)Database AnalystDatabase DeveloperDB DevelopmentEDI/Data Integration ExpertFirebirdHierarchicalIBM DB2InformixJava DatabaseMariaDBMicrosoft Access DeveloperMongoDBMS SQL ServerMySQL ProgrammingNetworkNoSQLObject RelationalPostgrePostgreSQLProgressRDBMSRelationalSQLSQL AdministratorSQL and PL/SQLSQL Notification ServicesSQL server 2008SSRSStored ProcedureSybaseTeradata
Copyright © 2018. All Rights Reserved
MS SQL Server Interview Question:
What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server?
Submitted by: AdministratorIf your table has a primary key column, and you are trying to insert a new row with duplicate key value on the primary key column, you will get an error. The reason is simple - Primary key column does not allow duplicate values. The following tutorial exercise gives you a good example:
SELECT * FROM ggl_links
INSERT INTO ggl_links VALUES (101,
'www.globalguideline.com',
NULL,
0,
'2006-04-30')
GO
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint
'PK__ggl_links__03317E3D'. Cannot insert duplicate
key in object 'dbo.ggl_links'.
The statement has been terminated.
You are getting this error, because value "101" has already been used by an existing row.
Submitted by: Administrator
SELECT * FROM ggl_links
INSERT INTO ggl_links VALUES (101,
'www.globalguideline.com',
NULL,
0,
'2006-04-30')
GO
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint
'PK__ggl_links__03317E3D'. Cannot insert duplicate
key in object 'dbo.ggl_links'.
The statement has been terminated.
You are getting this error, because value "101" has already been used by an existing row.
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.