Collections:
Duplicate Key Error on Primary Key Columns in SQL Server
What Happens If You Insert a Duplicate Key for the Primary Key Column in SQL Server?
✍: FYIcenter.com
If 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 fyi_links INSERT INTO fyi_links VALUES (101, 'sql.fyicenter.com', NULL, 0, '2006-04-30') GO Msg 2627, Level 14, State 1, Line 1 Violation of PRIMARY KEY constraint 'PK__fyi_links__03317E3D'. Cannot insert duplicate key in object 'dbo.fyi_links'. The statement has been terminated.
You are getting this error, because value "101" has already been used by an existing row.
⇒ Inserting Multiple Rows with One INSERT Statement in SQL Server
⇐ Providing Column Names in INSERT Statements in SQL Server
2016-11-02, 2143🔥, 0💬
Popular Posts:
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
What are DDL (Data Definition Language) statements for tables in SQL Server? DDL (Data Definition La...
What Is Oracle in Oracle? Oracle is a company. Oracle is also a database server, which manages data ...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...